本文整理汇总了Golang中github.com/couchbase/gocb.Connect函数的典型用法代码示例。如果您正苦于以下问题:Golang Connect函数的具体用法?Golang Connect怎么用?Golang Connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Connect函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
// Setup a new query with a placeholder
myQuery := gocb.NewN1qlQuery("SELECT airportname, city, country FROM `travel-sample` " +
"WHERE type='airport' AND city=$1 ")
// Setup an array for parameters
var myParams []interface{}
myParams = append(myParams, "Reno")
// Execute Query
rows, err := bucket.ExecuteN1qlQuery(myQuery, myParams)
if err != nil {
fmt.Println("ERROR EXECUTING N1QL QUERY:", err)
}
// Iterate through rows and print output
var row interface{}
for rows.Next(&row) {
fmt.Printf("Results: %+v\n", row)
}
// Exiting
fmt.Println("Example Successful - Exiting")
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:35,代码来源:query-placeholders.go
示例2: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
// Create a document
key := "goDevguideExampleRetrieve"
val := "Retrieve Test Value"
_, err = bucket.Upsert(key, &val, 0)
if err != nil {
fmt.Println("ERRROR CREATING DOCUMENT:", err)
}
// Retrieve Document
var retValue interface{}
_, err = bucket.Get(key, &retValue)
if err != nil {
fmt.Println("ERRROR RETURNING DOCUMENT:", err)
}
fmt.Println("Document Retrieved:", retValue)
// Exiting
fmt.Println("Example Successful - Exiting")
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:31,代码来源:retrieving.go
示例3: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
// Setup a new query for building an index
myQuery := gocb.NewN1qlQuery("CREATE PRIMARY INDEX ON `travel-sample`")
rows, err := bucket.ExecuteN1qlQuery(myQuery, nil)
if err != nil {
fmt.Println("ERROR EXECUTING N1QL QUERY:", err)
}
// Iterate through rows and print output
var row interface{}
for rows.Next(&row) {
fmt.Printf("Results: %+v\n", row)
}
// Exiting
fmt.Println("Example Successful - Exiting")
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:28,代码来源:query-create-index.go
示例4: userById
// userById attempts to return a JSON response for the supplied userid
// couchbase errors are handled in the handleError middleware method
func userById(c *gin.Context) {
myCluster, _ := gocb.Connect("couchbase://localhost")
myBucket, _ := myCluster.OpenBucket("gamesim-sample", "")
var value interface{}
_, err := myBucket.Get(c.Params.ByName("userid"), &value)
if err != nil {
c.Error(err).SetType(gin.ErrorTypePublic)
} else {
c.JSON(http.StatusOK, &value)
}
}
开发者ID:mhockenbury,项目名称:go-web-test,代码行数:13,代码来源:main.go
示例5: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
// Create a JSON document
type Doc struct {
Item string `json:"item"`
}
key := "goDevguideExampleBulkInsert"
val := Doc{"A bulk insert test value"}
// Create Array of BulkOps for Insert, and one for Get
var items []gocb.BulkOp
var itemsGet []gocb.BulkOp
// Add 10 items to the array that will be performed as a bulk operation
for i := 0; i < 10; i++ {
items = append(items, &gocb.InsertOp{Key: key + "_" + strconv.Itoa(i), Value: &val})
}
// Perform the bulk operation to Insert
err = bucket.Do(items)
if err != nil {
fmt.Println("ERRROR PERFORMING BULK INSERT:", err)
}
// Retrieve 10 items to the array that will be performed as a bulk operation
for i := 0; i < 10; i++ {
itemsGet = append(itemsGet, &gocb.GetOp{Key: key + "_" + strconv.Itoa(i), Value: &Doc{}})
}
// Perform the bulk operation to Get
err = bucket.Do(itemsGet)
if err != nil {
fmt.Println("ERRROR PERFORMING BULK GET:", err)
}
// Print the output
for i := 0; i < len(itemsGet); i++ {
fmt.Println(itemsGet[i].(*gocb.GetOp).Key, itemsGet[i].(*gocb.GetOp).Value.(*Doc).Item)
}
// Exiting
fmt.Println("Example Successful - Exiting")
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:54,代码来源:bulk-get.go
示例6: deleteBucket
func deleteBucket(host string, bucket string, t *testing.T, noErr bool) {
connection, err := gocb.Connect(host)
if err != nil {
t.Fatal("Unable to connect to cluster: " + err.Error())
}
manager := connection.Manager("Administrator", "password")
if err := manager.RemoveBucket(bucket); err != nil && !noErr {
t.Fatalf("Error deleting bucket %s", bucket)
}
}
开发者ID:couchbaselabs,项目名称:backuptests,代码行数:11,代码来源:common.go
示例7: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
fmt.Println("Example Successful - Exiting")
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:13,代码来源:connecting.go
示例8: NewGoCBStorageEngine
func NewGoCBStorageEngine(couchbaseUrl, bucketName string) *GoCBStorageEngine {
cluster, err := gocb.Connect(couchbaseUrl)
if err != nil {
log.Panicf("Could not connect to %v. Err: %v", couchbaseUrl, err)
}
bucket, err := cluster.OpenBucket(bucketName, "")
if err != nil {
log.Panicf("Could not open bucket: %v. Err: %v", bucket, err)
}
return &GoCBStorageEngine{
Bucket: bucket,
}
}
开发者ID:couchbaselabs,项目名称:go-couchbase-throughput,代码行数:14,代码来源:storage_engine.go
示例9: newGoCbClient
func newGoCbClient(serverURL string, bucketName string) *goCbClient {
cluster, err := gocb.Connect(serverURL)
if err != nil {
log.Fatalf("Could not connect to %v. Err: %v", serverURL, err)
}
bucket, err := cluster.OpenBucket(bucketName, "")
if err != nil {
log.Fatalf("Could not open bucket: %v. Err: %v", bucketName, err)
}
return &goCbClient{
bucket: bucket,
}
}
开发者ID:maniktaneja,项目名称:perf,代码行数:14,代码来源:main.go
示例10: userList
// userlist queries the playerlist view from the gamesim bucket and returns
// a JSON response containing all documents returned by the view
func userList(c *gin.Context) {
myCluster, _ := gocb.Connect("couchbase://localhost")
myBucket, _ := myCluster.OpenBucket("gamesim-sample", "")
myQuery := gocb.NewViewQuery("players", "playerlist")
rows := myBucket.ExecuteViewQuery(myQuery)
var results = make([]map[string]interface{}, 0)
var row interface{}
for rows.Next(&row) {
results = append(results, row.(map[string]interface{}))
}
c.JSON(http.StatusOK, &results)
}
开发者ID:mhockenbury,项目名称:go-web-test,代码行数:16,代码来源:main.go
示例11: main
func main() {
// Cluster connection and bucket for couchbase
cluster, _ := gocb.Connect("couchbase://127.0.0.1")
bucket, _ = cluster.OpenBucket("travel-sample", "")
// Http Routing
http.Handle("/", http.FileServer(http.Dir("./static")))
http.HandleFunc("/api/airport/findAll", airportHandler)
http.HandleFunc("/api/flightPath/findAll", flightPathHandler)
http.HandleFunc("/api/user/login", loginHandler)
http.HandleFunc("/api/user/flights", userFlightsHandler)
fmt.Printf("Starting server on :3000\n")
http.ListenAndServe(":3000", nil)
}
开发者ID:ToddGreenstein,项目名称:try-cb-golang,代码行数:14,代码来源:try.go
示例12: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
// Create a document
key := "goDevguideExampleUpdate"
val := "Retrieve Test Value"
_, err = bucket.Upsert(key, &val, 0)
if err != nil {
fmt.Println("ERRROR CREATING DOCUMENT:", err)
}
// Retrieve Document
var retValue interface{}
_, err = bucket.Get(key, &retValue)
if err != nil {
fmt.Println("ERRROR RETURNING DOCUMENT:", err)
}
fmt.Println("Document Retrieved:", retValue)
// Add something to the value
retValue = retValue.(string) + " with Additional Test Value"
// Replace the existing document
_, err = bucket.Replace(key, &retValue, 0, 0)
if err != nil {
fmt.Println("ERRROR REPLACING DOCUMENT:", err)
}
// Retrieve updated document
_, err = bucket.Get(key, &retValue)
if err != nil {
fmt.Println("ERRROR RETURNING DOCUMENT:", err)
}
fmt.Println("Document Retrieved:", retValue)
// Exiting
fmt.Println("Example Successful - Exiting")
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:47,代码来源:updating.go
示例13: deleteAllBuckets
func deleteAllBuckets(host string, t *testing.T) {
connection, err := gocb.Connect(host)
if err != nil {
t.Fatal("Unable to connect to cluster: " + err.Error())
}
manager := connection.Manager("Administrator", "password")
buckets, err := manager.GetBuckets()
if err != nil {
t.Fatal("Unable to get all buckets: " + err.Error())
}
for _, bucket := range buckets {
if err := manager.RemoveBucket(bucket.Name); err != nil {
t.Fatalf("Error deleting bucket %s", bucket.Name)
}
}
}
开发者ID:couchbaselabs,项目名称:backuptests,代码行数:18,代码来源:common.go
示例14: IndexHandler
func IndexHandler(w http.ResponseWriter, r *http.Request) {
cluster, _ := gocb.Connect("couchbase://localhost")
bucket, _ := cluster.OpenBucket("default", "")
value := "test"
cas, _ := bucket.Insert("snake", &value, 0)
fmt.Printf("Inserted document CAS is `%08x`\n", cas)
snake := lib.Snake{
Points: lib.Points{
lib.Point{
X: 1,
Y: 2,
},
},
}
json.NewEncoder(w).Encode(snake)
}
开发者ID:Intai,项目名称:intai-me-go,代码行数:19,代码来源:handlers.go
示例15: GetCouchbaseBucketGoCB
// Creates a Bucket that talks to a real live Couchbase server.
func GetCouchbaseBucketGoCB(spec BucketSpec) (bucket Bucket, err error) {
// Only wrap the gocb logging when the log key is set, to avoid the overhead of a log keys
// map lookup for every gocb log call
logKeys := GetLogKeys()
if logKeys["gocb"] {
EnableGoCBLogging()
}
cluster, err := gocb.Connect(spec.Server)
if err != nil {
return nil, err
}
password := ""
if spec.Auth != nil {
_, password, _ = spec.Auth.GetCredentials()
}
goCBBucket, err := cluster.OpenBucket(spec.BucketName, password)
if err != nil {
return nil, err
}
spec.MaxNumRetries = 10
spec.InitialRetrySleepTimeMS = 5
// Define channels to limit the number of concurrent single and bulk operations,
// to avoid gocb queue overflow issues
bucket = CouchbaseBucketGoCB{
goCBBucket,
spec,
make(chan struct{}, MaxConcurrentSingleOps),
make(chan struct{}, MaxConcurrentBulkOps),
}
return bucket, err
}
开发者ID:paulharter,项目名称:sync_gateway,代码行数:42,代码来源:bucket_gocb.go
示例16: BenchmarkCouchBaseInsertgocb
func BenchmarkCouchBaseInsertgocb(b *testing.B) {
var err error
insertUsers := make([]*User, len(couchBaseTestUsers))
copy(insertUsers, couchBaseTestUsers)
db_url, err := url.Parse(*couchBaseUrl)
mf(err, "parse", b)
cluster, err := gocb.Connect(db_url.String())
mf(err, "connect - "+db_url.String(), b)
bucket, err := cluster.OpenBucket(*couchBaseBucket, "")
mf(err, "bucket", b)
b.ResetTimer()
for i := 0; i < b.N; i++ {
user := getUser(i, uuid.NewV4().String(), &couchBaseTestUsers)
_, err := bucket.Insert(user.Id, user, 0)
mf(err, "Insert", b)
}
}
开发者ID:YotpoLtd,项目名称:dbenchmark,代码行数:21,代码来源:kvbench.go
示例17: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER:", err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("travel-sample", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET:", err)
}
// Inbound http handlers
http.Handle("/", http.FileServer(http.Dir("./public")))
http.HandleFunc("/api/query/untyped", queryUntyped)
http.HandleFunc("/api/query/typed", queryTyped)
http.HandleFunc("/api/query/one", queryOne)
fmt.Printf("Starting server on :3000\n")
http.ListenAndServe(":3000", nil)
}
开发者ID:Branor,项目名称:devguide-examples,代码行数:21,代码来源:query-marshalling-rest.go
示例18: BenchmarkCouchBaseGetgocb
func BenchmarkCouchBaseGetgocb(b *testing.B) {
var err error
db_url, err := url.Parse(*couchBaseUrl)
mf(err, "parse", b)
cluster, err := gocb.Connect(db_url.String())
mf(err, "connect - "+db_url.String(), b)
bucket, err := cluster.OpenBucket(*couchBaseBucket, "")
mf(err, "bucket", b)
b.ResetTimer()
max := len(couchBaseTestUsers)
for i := 0; i < b.N; i++ {
user := &User{}
_, err := bucket.Get(couchBaseTestUsers[rand.Intn(max)].Id, *user)
mf(err, "Get", b)
}
}
开发者ID:YotpoLtd,项目名称:dbenchmark,代码行数:21,代码来源:kvbench.go
示例19: loadData
func loadData(host string, bucket string, password string, items int,
prefix string, t *testing.T) {
connection, err := gocb.Connect(host)
if err != nil {
t.Fatal("Test data loader cannot connect to the cluster: " + err.Error())
}
b, err := connection.OpenBucket(bucket, password)
if err != nil {
t.Fatal("Test data loader cannot connect to the bucket: " + err.Error())
}
for i := 0; i < items; i++ {
key := prefix + strconv.Itoa(i)
_, err := b.Insert(key, map[string]interface{}{"x": i}, 0)
if err != nil {
t.Fatal("Error setting `" + key + "`, " + err.Error())
}
}
b.Close()
}
开发者ID:couchbaselabs,项目名称:backuptests,代码行数:21,代码来源:common.go
示例20: main
func main() {
// Connect to Cluster
cluster, err := gocb.Connect("couchbase://127.0.0.1")
if err != nil {
fmt.Println("ERRROR CONNECTING TO CLUSTER")
panic(err)
}
// Open Bucket
bucket, err = cluster.OpenBucket("default", "")
if err != nil {
fmt.Println("ERRROR OPENING BUCKET")
panic(err)
}
fmt.Println("==> Enter keyword(s):")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
word := strings.Replace(scanner.Text(), " ", "+", -1)
meaning, err := lib.GetURL(lib.URL + word)
if err != nil {
fmt.Println("Error fetching from urbandictionary.com")
panic(err)
}
cas, err2 := lib.Upsert(bucket, word, meaning)
if err2 != nil {
fmt.Println(err2)
}
fmt.Printf("Inserted document CAS is `%08x`\n", cas)
fmt.Println("==> Enter keyword(s):")
}
}
开发者ID:rudijs,项目名称:urban,代码行数:40,代码来源:main.go
注:本文中的github.com/couchbase/gocb.Connect函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论