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


Golang Context.HTTPRequestScheme方法代码示例

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


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

示例3: 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.HTTPRequestScheme() + "://" + baseURL,
	}
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:20,代码来源:http.go

示例4: 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


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