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

Golang base.Context类代码示例

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

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



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

示例1: main

func main() {
	flag.Parse()

	ctx := base.Context{Insecure: *insecure, Certs: *certs, User: *user}
	httpClient, err := ctx.GetHTTPClient()
	if err != nil {
		panic(err)
	}

	startTime := time.Now()
	file := filepath.Join(*outputDir, fmt.Sprintf("monitor.%s", strings.Replace(
		startTime.Format(time.RFC3339), ":", "_", -1)))
	log.Infof("Logging cluster status to: %s.\n", file)
	w, err := os.Create(file)
	if err != nil {
		panic(err)
	}
	defer w.Close()

	url := fmt.Sprintf("%s://%s/%s", ctx.HTTPRequestScheme(), *addr, *endpoint)
	log.Infof("Cluster Status URL: %s\n", url)

	for range time.Tick(*interval) {
		resp, found := request(url, httpClient)
		if !found {
			log.Warningf("Could not get cluster status. Time since monitor started %s.", time.Since(startTime))
			break
		}
		log.Infof("Got cluster status.")
		fmt.Fprintf(w, "%s\n", resp)
	}
}
开发者ID:rissoa,项目名称:cockroach,代码行数:32,代码来源:main.go


示例2: newStatusServer

// newStatusServer allocates and returns a statusServer.
func newStatusServer(
	db *client.DB,
	gossip *gossip.Gossip,
	metricSource json.Marshaler,
	ctx *base.Context,
	rpcCtx *rpc.Context,
	stores *storage.Stores,
) *statusServer {
	// Create an http client with a timeout
	httpClient, err := ctx.GetHTTPClient()
	if err != nil {
		log.Error(err)
		return nil
	}

	server := &statusServer{
		db:           db,
		gossip:       gossip,
		metricSource: metricSource,
		router:       httprouter.New(),
		rpcCtx:       rpcCtx,
		proxyClient:  httpClient,
		stores:       stores,
	}

	server.router.GET(statusLogFilesListPattern, server.handleLogFilesList)
	server.router.GET(statusLogFilePattern, server.handleLogFile)
	server.router.GET(statusLogsPattern, server.handleLogs)
	// TODO(tschottdorf): significant overlap with /debug/pprof/goroutine,
	// except that this one allows querying by NodeID.
	server.router.GET(statusStacksPattern, server.handleStacks)
	server.router.GET(statusMetricsPattern, server.handleMetrics)

	return server
}
开发者ID:JKhawaja,项目名称:cockroach,代码行数:36,代码来源:status.go


示例3: makeTestHTTPSession

// makeTestHTTPSession constructs a new testHTTPSession. The session will
// instantiate a client using the based base context. All HTTP requests from the
// session will be sent to the given baseUrl.
//
// baseUrl should be specified *without* a request scheme (i.e. "http://"); the
// request scheme will be used from the context.
//
// If an error occurs in HTTP layer during any session operation, a Fatal method
// will be called on the supplied t.Tester.
func makeTestHTTPSession(t *testing.T, ctx *base.Context, baseURL string) testHTTPSession {
	client, err := ctx.GetHTTPClient()
	if err != nil {
		t.Fatalf("error creating client: %s", err)
	}
	return testHTTPSession{
		client:  client,
		baseURL: ctx.HTTPRequestScheme() + "://" + baseURL,
	}
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:19,代码来源:http_session_test.go


示例4: NewTestHTTPSession

// NewTestHTTPSession constructs a new TestHTTPSession. The session will
// instantiate a client using the based base context. All HTTP requests from the
// session will be sent to the given baseUrl.
//
// baseUrl should be specified *without* a request scheme (i.e. "http://"); the
// request scheme will be used from the context.
//
// If an error occurs in HTTP layer during any session operation, a Fatal method
// will be called on the supplied t.Tester.
func NewTestHTTPSession(t util.Tester, ctx *base.Context, baseURL string) *TestHTTPSession {
	client, err := ctx.GetHTTPClient()
	if err != nil {
		t.Fatalf("error creating client: %s", err)
	}
	return &TestHTTPSession{
		t:       t,
		client:  client,
		baseURL: ctx.RequestScheme() + "://" + baseURL,
	}
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:20,代码来源:http.go


示例5: newStatusMonitor

func newStatusMonitor(context *base.Context, addr string) (*statusMonitor, error) {
	monitor := &statusMonitor{
		addr: addr,
	}
	var err error
	monitor.httpClient, err = context.GetHTTPClient()
	if err != nil {
		return nil, err
	}
	monitor.url = fmt.Sprintf("%s://%s/%s", context.HTTPRequestScheme(), monitor.addr, urlPath)
	return monitor, nil
}
开发者ID:mbertschler,项目名称:cockroach,代码行数:12,代码来源:main.go


示例6: newHTTPSender

// newHTTPSender returns a new instance of httpSender.
func newHTTPSender(server string, ctx *base.Context, retryOpts retry.Options) (*httpSender, error) {
	sender := &httpSender{
		server:    server,
		context:   ctx,
		retryOpts: retryOpts,
	}
	var err error
	sender.client, err = ctx.GetHTTPClient()
	if err != nil {
		return nil, err
	}
	return sender, nil
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:14,代码来源:http_sender.go


示例7: newHTTPSender

// newHTTPSender returns a new instance of httpSender.
func newHTTPSender(server string, ctx *base.Context, retryOpts retry.Options) (*httpSender, error) {
	// Ensure that the context returns an HTTPClient.
	if _, err := ctx.GetHTTPClient(); err != nil {
		return nil, err
	}

	return &httpSender{
		ctx: client.PostContext{
			Server:    server,
			Endpoint:  Endpoint,
			Context:   ctx,
			RetryOpts: retryOpts,
		},
	}, nil
}
开发者ID:Eric-Gaudiello,项目名称:cockroach,代码行数:16,代码来源:http_sender.go


示例8: newRPCSender

// newRPCSender returns a new instance of rpcSender.
func newRPCSender(server string, context *base.Context, retryOpts retry.Options) (*rpcSender, error) {
	addr, err := net.ResolveTCPAddr("tcp", server)
	if err != nil {
		return nil, err
	}

	tlsConfig, err := context.GetClientTLSConfig()
	if err != nil {
		return nil, err
	}

	conn, err := codec.TLSDialHTTP(addr.Network(), addr.String(), base.NetworkTimeout, tlsConfig)
	if err != nil {
		return nil, err
	}

	client := rpc.NewClientWithCodec(codec.NewClientCodec(conn))
	return &rpcSender{
		user:      context.User,
		client:    client,
		retryOpts: retryOpts,
	}, nil
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:24,代码来源:rpc_sender.go


示例9: createTestClientForUser

func createTestClientForUser(t *testing.T, stopper *stop.Stopper, addr, user string) *client.DB {
	var ctx base.Context
	ctx.InitDefaults()
	ctx.User = user
	ctx.SSLCA = filepath.Join(security.EmbeddedCertsDir, security.EmbeddedCACert)
	ctx.SSLCert = filepath.Join(security.EmbeddedCertsDir, fmt.Sprintf("%s.crt", user))
	ctx.SSLCertKey = filepath.Join(security.EmbeddedCertsDir, fmt.Sprintf("%s.key", user))
	sender, err := client.NewSender(rpc.NewContext(&ctx, nil, stopper), addr)
	if err != nil {
		t.Fatal(err)
	}
	return client.NewDB(sender)
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:13,代码来源:db_test.go


示例10: newRPCSender

// newRPCSender returns a new instance of rpcSender.
func newRPCSender(server string, context *base.Context, retryOpts retry.Options, stopper *stop.Stopper) (*rpcSender, error) {
	addr, err := net.ResolveTCPAddr("tcp", server)
	if err != nil {
		return nil, err
	}

	if context.Insecure {
		log.Warning("running in insecure mode, this is strongly discouraged. See --insecure and --certs.")
	} else {
		if _, err := context.GetClientTLSConfig(); err != nil {
			return nil, err
		}
	}

	ctx := rpc.NewContext(context, hlc.NewClock(hlc.UnixNano), stopper)
	client := rpc.NewClient(addr, ctx)
	return &rpcSender{
		client:    client,
		retryOpts: retryOpts,
	}, nil
}
开发者ID:husttom,项目名称:cockroach,代码行数:22,代码来源:rpc_sender.go


示例11: fillCertPaths

func fillCertPaths(context *base.Context, user string) {
	context.SSLCA = filepath.Join(security.EmbeddedCertsDir, security.EmbeddedCACert)
	context.SSLCAKey = filepath.Join(security.EmbeddedCertsDir, security.EmbeddedCAKey)
	context.SSLCert = filepath.Join(security.EmbeddedCertsDir, fmt.Sprintf("%s.crt", user))
	context.SSLCertKey = filepath.Join(security.EmbeddedCertsDir, fmt.Sprintf("%s.key", user))
}
开发者ID:GitGoldie,项目名称:cockroach,代码行数:6,代码来源:context_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang build.GetInfo函数代码示例发布时间:2022-05-23
下一篇:
Golang base.DefaultRetryOptions函数代码示例发布时间: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