• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang client.Open函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了Open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: createTestClient

func createTestClient(addr string) *client.DB {
	db, err := client.Open("https://[email protected]" + addr + "?certs=" + security.EmbeddedCertsDir)
	if err != nil {
		log.Fatal(err)
	}
	return db
}
开发者ID:simonzhangsm,项目名称:cockroach,代码行数:7,代码来源:client_test.go


示例2: Open

func (d *roachDriver) Open(dsn string) (driver.Conn, error) {
	db, err := client.Open(dsn)
	if err != nil {
		return nil, err
	}
	u, err := url.Parse(dsn)
	if err != nil {
		return nil, err
	}
	ctx := &base.Context{}
	ctx.InitDefaults()
	if u.User != nil {
		ctx.User = u.User.Username()
	}
	q := u.Query()
	if dir := q["certs"]; len(dir) > 0 {
		ctx.Certs = dir[0]
	}

	sender, err := newHTTPSender(u.Host, ctx, client.DefaultTxnRetryOptions)
	if err != nil {
		return nil, err
	}
	return &conn{db: db, sender: sender}, nil
}
开发者ID:simonzhangsm,项目名称:cockroach,代码行数:25,代码来源:driver.go


示例3: Open

func (d *roachDriver) Open(dsn string) (driver.Conn, error) {
	db, err := client.Open(dsn)
	if err != nil {
		return nil, err
	}
	return &conn{db: db}, nil
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:7,代码来源:driver.go


示例4: Start

// Start starts the test cluster by bootstrapping an in-memory store
// (defaults to maximum of 50M). The server is started, launching the
// node RPC server and all HTTP endpoints. Use the value of
// TestServer.Addr after Start() for client connections. Use Stop()
// to shutdown the server after the test completes.
func (ltc *LocalTestCluster) Start(t util.Tester) {
	ltc.Manual = hlc.NewManualClock(0)
	ltc.Clock = hlc.NewClock(ltc.Manual.UnixNano)
	ltc.Stopper = stop.NewStopper()
	rpcContext := rpc.NewContext(testutils.NewRootTestBaseContext(), ltc.Clock, ltc.Stopper)
	ltc.Gossip = gossip.New(rpcContext, gossip.TestInterval, gossip.TestBootstrap)
	ltc.Eng = engine.NewInMem(proto.Attributes{}, 50<<20)
	ltc.lSender = newRetryableLocalSender(NewLocalSender())
	ltc.Sender = NewTxnCoordSender(ltc.lSender, ltc.Clock, false, nil, ltc.Stopper)
	var err error
	if ltc.DB, err = client.Open("//[email protected]", client.SenderOpt(ltc.Sender)); err != nil {
		t.Fatal(err)
	}
	transport := multiraft.NewLocalRPCTransport(ltc.Stopper)
	ltc.Stopper.AddCloser(transport)
	ctx := storage.TestStoreContext
	ctx.Clock = ltc.Clock
	ctx.DB = ltc.DB
	ctx.Gossip = ltc.Gossip
	ctx.Transport = transport
	ltc.Store = storage.NewStore(ctx, ltc.Eng, &proto.NodeDescriptor{NodeID: 1})
	if err := ltc.Store.Bootstrap(proto.StoreIdent{NodeID: 1, StoreID: 1}, ltc.Stopper); err != nil {
		t.Fatalf("unable to start local test cluster: %s", err)
	}
	ltc.lSender.AddStore(ltc.Store)
	if err := ltc.Store.BootstrapRange(nil); err != nil {
		t.Fatalf("unable to start local test cluster: %s", err)
	}
	if err := ltc.Store.Start(ltc.Stopper); err != nil {
		t.Fatalf("unable to start local test cluster: %s", err)
	}
}
开发者ID:knorwood,项目名称:cockroach,代码行数:37,代码来源:local_test_cluster.go


示例5: createTestStoreWithoutStart

// createTestStoreWithoutStart creates a test store using an in-memory
// engine without starting the store. It returns the store, the store
// clock's manual unix nanos time and a stopper. The caller is
// responsible for stopping the stopper upon completion.
func createTestStoreWithoutStart(t *testing.T) (*Store, *hlc.ManualClock, *stop.Stopper) {
	stopper := stop.NewStopper()
	rpcContext := rpc.NewContext(rootTestBaseContext, hlc.NewClock(hlc.UnixNano), stopper)
	ctx := TestStoreContext
	ctx.Gossip = gossip.New(rpcContext, gossip.TestInterval, gossip.TestBootstrap)
	manual := hlc.NewManualClock(0)
	ctx.Clock = hlc.NewClock(manual.UnixNano)
	eng := engine.NewInMem(proto.Attributes{}, 10<<20)
	ctx.Transport = multiraft.NewLocalRPCTransport()
	stopper.AddCloser(ctx.Transport)
	sender := &testSender{}
	var err error
	if ctx.DB, err = client.Open("//[email protected]", client.SenderOpt(sender)); err != nil {
		t.Fatal(err)
	}
	store := NewStore(ctx, eng, &proto.NodeDescriptor{NodeID: 1})
	sender.store = store
	if err := store.Bootstrap(proto.StoreIdent{NodeID: 1, StoreID: 1}, stopper); err != nil {
		t.Fatal(err)
	}
	if err := store.BootstrapRange(); err != nil {
		t.Fatal(err)
	}
	return store, manual, stopper
}
开发者ID:backend2use,项目名称:cockroachdb,代码行数:29,代码来源:store_test.go


示例6: createTestNode

// createTestNode creates an rpc server using the specified address,
// gossip instance, KV database and a node using the specified slice
// of engines. The server, clock and node are returned. If gossipBS is
// not nil, the gossip bootstrap address is set to gossipBS.
func createTestNode(addr net.Addr, engines []engine.Engine, gossipBS net.Addr, t *testing.T) (
	*rpc.Server, *hlc.Clock, *Node, *stop.Stopper) {
	var err error
	ctx := storage.StoreContext{}

	stopper := stop.NewStopper()
	ctx.Clock = hlc.NewClock(hlc.UnixNano)
	nodeRPCContext := rpc.NewContext(nodeTestBaseContext, ctx.Clock, stopper)
	ctx.ScanInterval = 10 * time.Hour
	rpcServer := rpc.NewServer(addr, nodeRPCContext)
	if err := rpcServer.Start(); err != nil {
		t.Fatal(err)
	}
	g := gossip.New(nodeRPCContext, testContext.GossipInterval, testContext.GossipBootstrapResolvers)
	if gossipBS != nil {
		// Handle possibility of a :0 port specification.
		if gossipBS == addr {
			gossipBS = rpcServer.Addr()
		}
		g.SetResolvers([]resolver.Resolver{resolver.NewResolverFromAddress(gossipBS)})
		g.Start(rpcServer, stopper)
	}
	ctx.Gossip = g
	sender := kv.NewDistSender(&kv.DistSenderContext{Clock: ctx.Clock}, g)
	if ctx.DB, err = client.Open("//[email protected]", client.SenderOpt(sender)); err != nil {
		t.Fatal(err)
	}
	// TODO(bdarnell): arrange to have the transport closed.
	// (or attach LocalRPCTransport.Close to the stopper)
	ctx.Transport = multiraft.NewLocalRPCTransport(stopper)
	ctx.EventFeed = util.NewFeed(stopper)
	node := NewNode(ctx)
	return rpcServer, ctx.Clock, node, stopper
}
开发者ID:ErikGrimes,项目名称:cockroach,代码行数:38,代码来源:node_test.go


示例7: BootstrapCluster

// BootstrapCluster bootstraps a multiple stores using the provided engines and
// cluster ID. The first bootstrapped store contains a single range spanning
// all keys. Initial range lookup metadata is populated for the range.
//
// Returns a KV client for unittest purposes. Caller should close the returned
// client.
func BootstrapCluster(clusterID string, engines []engine.Engine, stopper *stop.Stopper) (*client.DB, error) {
	ctx := storage.StoreContext{}
	ctx.ScanInterval = 10 * time.Minute
	ctx.Clock = hlc.NewClock(hlc.UnixNano)
	// Create a KV DB with a local sender.
	lSender := kv.NewLocalSender()
	sender := kv.NewTxnCoordSender(lSender, ctx.Clock, false, nil, stopper)
	var err error
	if ctx.DB, err = client.Open("//[email protected]", client.SenderOpt(sender)); err != nil {
		return nil, err
	}
	ctx.Transport = multiraft.NewLocalRPCTransport(stopper)
	for i, eng := range engines {
		sIdent := proto.StoreIdent{
			ClusterID: clusterID,
			NodeID:    1,
			StoreID:   proto.StoreID(i + 1),
		}

		// The bootstrapping store will not connect to other nodes so its
		// StoreConfig doesn't really matter.
		s := storage.NewStore(ctx, eng, &proto.NodeDescriptor{NodeID: 1})

		// Verify the store isn't already part of a cluster.
		if len(s.Ident.ClusterID) > 0 {
			return nil, util.Errorf("storage engine already belongs to a cluster (%s)", s.Ident.ClusterID)
		}

		// Bootstrap store to persist the store ident.
		if err := s.Bootstrap(sIdent, stopper); err != nil {
			return nil, err
		}
		// Create first range, writing directly to engine. Note this does
		// not create the range, just its data.  Only do this if this is the
		// first store.
		if i == 0 {
			if err := s.BootstrapRange(); err != nil {
				return nil, err
			}
		}
		if err := s.Start(stopper); err != nil {
			return nil, err
		}

		lSender.AddStore(s)

		// Initialize node and store ids.  Only initialize the node once.
		if i == 0 {
			if nodeID, err := allocateNodeID(ctx.DB); nodeID != sIdent.NodeID || err != nil {
				return nil, util.Errorf("expected to initialize node id allocator to %d, got %d: %s",
					sIdent.NodeID, nodeID, err)
			}
		}
		if storeID, err := allocateStoreIDs(sIdent.NodeID, 1, ctx.DB); storeID != sIdent.StoreID || err != nil {
			return nil, util.Errorf("expected to initialize store id allocator to %d, got %d: %s",
				sIdent.StoreID, storeID, err)
		}
	}
	return ctx.DB, nil
}
开发者ID:arypurnomoz,项目名称:cockroach,代码行数:66,代码来源:node.go


示例8: ExampleDB_Put_insecure

func ExampleDB_Put_insecure() {
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = true
	if pErr := s.Start(); pErr != nil {
		log.Fatalf("Could not start server: %v", pErr)
	}
	defer s.Stop()

	db, err := client.Open(s.Stopper(), "rpc://[email protected]"+s.ServingAddr())
	if err != nil {
		log.Fatal(err)
	}

	if pErr := db.Put("aa", "1"); pErr != nil {
		panic(pErr)
	}
	result, pErr := db.Get("aa")
	if pErr != nil {
		panic(pErr)
	}
	fmt.Printf("aa=%s\n", result.ValueBytes())

	// Output:
	// aa=1
}
开发者ID:eddyzhou,项目名称:cockroach,代码行数:26,代码来源:db_test.go


示例9: ExampleDB_Insecure

func ExampleDB_Insecure() {
	s := &server.TestServer{}
	s.Ctx = server.NewTestContext()
	s.Ctx.Insecure = true
	if err := s.Start(); err != nil {
		log.Fatalf("Could not start server: %v", err)
	}
	log.Printf("Test server listening on %s: %s", s.Ctx.RequestScheme(), s.ServingAddr())
	defer s.Stop()

	db, err := client.Open("http://[email protected]" + s.ServingAddr())
	if err != nil {
		log.Fatal(err)
	}

	if err := db.Put("aa", "1"); err != nil {
		panic(err)
	}
	result, err := db.Get("aa")
	if err != nil {
		panic(err)
	}
	fmt.Printf("aa=%s\n", result.ValueBytes())

	// Output:
	// aa=1
}
开发者ID:routhcr,项目名称:cockroach,代码行数:27,代码来源:db_test.go


示例10: createTestClientFor

func createTestClientFor(stopper *stop.Stopper, addr, user string) *client.DB {
	db, err := client.Open(stopper, "rpcs://"+user+"@"+addr+"?certs="+security.EmbeddedCertsDir)
	if err != nil {
		log.Fatal(err)
	}
	return db
}
开发者ID:abhishekgahlot,项目名称:cockroach,代码行数:7,代码来源:client_test.go


示例11: makeClient

func makeClient(t *testing.T, str string) (*client.DB, *stop.Stopper) {
	stopper := stop.NewStopper()
	db, err := client.Open(stopper, str)
	if err != nil {
		t.Fatal(err)
	}
	return db, stopper
}
开发者ID:soniabhishek,项目名称:cockroach,代码行数:8,代码来源:main_test.go


示例12: createTestClientForUser

func createTestClientForUser(t *testing.T, addr, user string) *client.DB {
	db, err := client.Open(fmt.Sprintf("https://%[email protected]%s?certs=%s",
		user, addr, security.EmbeddedCertsDir))
	if err != nil {
		t.Fatal(err)
	}
	return db
}
开发者ID:Eric-Gaudiello,项目名称:cockroach,代码行数:8,代码来源:db_test.go


示例13: createTestClientForUser

func createTestClientForUser(t *testing.T, stopper *stop.Stopper, addr, user string) *client.DB {
	db, err := client.Open(stopper, fmt.Sprintf("rpcs://%[email protected]%s?certs=%s&failfast=1",
		user, addr, security.EmbeddedCertsDir))
	if err != nil {
		t.Fatal(err)
	}
	return db
}
开发者ID:husttom,项目名称:cockroach,代码行数:8,代码来源:db_test.go


示例14: setup

func setup() (*server.TestServer, *client.DB) {
	s := server.StartTestServer(nil)
	db, err := client.Open("https://[email protected]" + s.ServingAddr() + "?certs=test_certs")
	if err != nil {
		log.Fatal(err)
	}
	return s, db
}
开发者ID:routhcr,项目名称:cockroach,代码行数:8,代码来源:db_test.go


示例15: createTestNotifyClient

// createTestNotifyClient creates a new client which connects using an HTTP
// sender to the server at addr. It contains a waitgroup to allow waiting.
func createTestNotifyClient(addr string, priority int) (*client.DB, *notifyingSender) {
	db, err := client.Open(fmt.Sprintf("https://[email protected]%s?certs=%s&priority=%d",
		addr, security.EmbeddedCertsDir, priority))
	if err != nil {
		log.Fatal(err)
	}
	sender := &notifyingSender{wrapped: db.Sender}
	db.Sender = sender
	return db, sender
}
开发者ID:simonzhangsm,项目名称:cockroach,代码行数:12,代码来源:client_test.go


示例16: setup

func setup() (*server.TestServer, *client.DB) {
	s := server.StartTestServer(nil)
	db, err := client.Open(s.Stopper(), fmt.Sprintf("rpcs://%[email protected]%s?certs=test_certs",
		security.NodeUser,
		s.ServingAddr()))
	if err != nil {
		log.Fatal(err)
	}
	return s, db
}
开发者ID:alunarbeach,项目名称:cockroach,代码行数:10,代码来源:db_test.go


示例17: WritePermissionConfig

// WritePermissionConfig writes the passed-in 'cfg' permissions config
// for the 'path' key prefix.
func (ts *TestServer) WritePermissionConfig(path string, cfg *proto.PermConfig) error {
	// The testserver is running as "node". However, things like config changes are generally
	// done as root.
	db, err := client.Open(ts.Ctx.RequestScheme() + "://[email protected]" + ts.ServingAddr() + "?certs=test_certs")
	if err != nil {
		return err
	}
	key := keys.MakeKey(keys.ConfigPermissionPrefix, proto.Key(path))
	return db.Put(key, cfg)
}
开发者ID:XisiHuang,项目名称:cockroach,代码行数:12,代码来源:testserver.go


示例18: makeClient

func makeClient() *client.DB {
	stopper := stop.NewStopper()

	addr := fmt.Sprintf("rpc://[email protected]:9001?certs=certs")
	// Create a database handle.
	db, err := client.Open(stopper, addr)
	if err != nil {
		panic(fmt.Sprintf("open client fail. addr: %v, err: %v\n", addr, err))
	}

	return db
}
开发者ID:YuleiXiao,项目名称:ccclient,代码行数:12,代码来源:main.go


示例19: createTestNotifyClient

// createTestNotifyClient creates a new client which connects using an HTTP
// sender to the server at addr. It contains a waitgroup to allow waiting.
func createTestNotifyClient(stopper *stop.Stopper, addr string, priority roachpb.UserPriority) (*client.DB, *notifyingSender) {
	db, err := client.Open(stopper, fmt.Sprintf("rpcs://%[email protected]%s?certs=%s",
		security.NodeUser,
		addr,
		security.EmbeddedCertsDir))
	if err != nil {
		log.Fatal(err)
	}

	sender := &notifyingSender{wrapped: db.GetSender()}
	return client.NewDBWithPriority(sender, priority), sender
}
开发者ID:guowenfei-mathsfan,项目名称:cockroach,代码行数:14,代码来源:client_test.go


示例20: makeDBClient

func makeDBClient() *client.DB {
	// TODO(pmattis): Initialize the user to something more
	// reasonable. Perhaps Context.Addr should be considered a URL.
	db, err := client.Open(Context.RequestScheme() +
		"://[email protected]" + Context.Addr +
		"?certs=" + Context.Certs)
	if err != nil {
		fmt.Fprintf(osStderr, "failed to initialize KV client: %s", err)
		osExit(1)
	}
	return db
}
开发者ID:backend2use,项目名称:cockroachdb,代码行数:12,代码来源:kv.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang client.SendCall函数代码示例发布时间:2022-05-23
下一篇:
Golang client.NewTxn函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap