当前位置: 首页>>代码示例>>Golang>>正文


Golang gocb.Connect函数代码示例

本文整理汇总了Golang中github.com/couchbase/gocb.Connect函数的典型用法代码示例。如果您正苦于以下问题:Golang Connect函数的具体用法?Golang Connect怎么用?Golang Connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的github.com/couchbase/gocb.Connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。