本文整理汇总了Golang中google/golang.org/cloud/internal/transport.NewHTTPClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHTTPClient函数的具体用法?Golang NewHTTPClient怎么用?Golang NewHTTPClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewHTTPClient函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewClient
// NewClient returns a new log client, logging to the named log in the
// provided project.
//
// The exported fields on the returned client may be modified before
// the client is used for logging. Once log entries are in flight,
// the fields must not be modified.
func NewClient(ctx context.Context, projectID, logName string, opts ...cloud.ClientOption) (*Client, error) {
httpClient, endpoint, err := transport.NewHTTPClient(ctx, append([]cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(Scope),
cloud.WithUserAgent(userAgent),
}, opts...)...)
if err != nil {
return nil, err
}
svc, err := api.New(httpClient)
if err != nil {
return nil, err
}
svc.BasePath = endpoint
c := &Client{
svc: svc,
logs: api.NewProjectsLogsEntriesService(svc),
logName: logName,
projID: projectID,
}
for i := range c.writer {
level := Level(i)
c.writer[level] = levelWriter{level, c}
c.logger[level] = log.New(c.writer[level], "", 0)
}
return c, nil
}
示例2: NewClient
// NewClient creates a new PubSub client.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
var o []cloud.ClientOption
// Environment variables for gcloud emulator:
// https://cloud.google.com/sdk/gcloud/reference/beta/emulators/pubsub/
if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" {
o = []cloud.ClientOption{
cloud.WithEndpoint("http://" + addr + "/"),
cloud.WithBaseHTTP(http.DefaultClient),
}
} else {
o = []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(raw.PubsubScope, raw.CloudPlatformScope),
cloud.WithUserAgent(userAgent),
}
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
s, err := newPubSubService(httpClient, endpoint)
if err != nil {
return nil, fmt.Errorf("constructing pubsub client: %v", err)
}
c := &Client{
projectID: projectID,
s: s,
}
return c, nil
}
示例3: NewClient
// NewClient creates a new Google Cloud Storage client.
func NewClient(ctx context.Context, opts ...cloud.ClientOption) (*Client, error) {
hc, _, err := transport.NewHTTPClient(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
rawService, err := raw.New(hc)
if err != nil {
return nil, fmt.Errorf("storage client: %v", err)
}
return &Client{
hc: hc,
raw: rawService,
}, nil
}
示例4: NewClient
// NewClient creates a new Google Cloud Storage client.
// The default scope is ScopeFullControl. To use a different scope, like ScopeReadOnly, use cloud.WithScopes.
func NewClient(ctx context.Context, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithScopes(ScopeFullControl),
cloud.WithUserAgent(userAgent),
}
opts = append(o, opts...)
hc, _, err := transport.NewHTTPClient(ctx, opts...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
rawService, err := raw.New(hc)
if err != nil {
return nil, fmt.Errorf("storage client: %v", err)
}
return &Client{
hc: hc,
raw: rawService,
}, nil
}
示例5: NewClient
// NewClient create a new PubSub client.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(raw.PubsubScope, raw.CloudPlatformScope),
cloud.WithUserAgent(userAgent),
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
s, err := newPubSubService(httpClient, endpoint)
c := &Client{
projectID: projectID,
s: s,
}
return c, nil
}
示例6: NewClient
// NewClient constructs a new Client which can perform BigQuery operations.
// Operations performed via the client are billed to the specified GCP project.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithEndpoint(prodAddr),
cloud.WithScopes(Scope),
cloud.WithUserAgent(userAgent),
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
s, err := newBigqueryService(httpClient, endpoint)
if err != nil {
return nil, fmt.Errorf("constructing bigquery client: %v", err)
}
c := &Client{
service: s,
projectID: projectID,
}
return c, nil
}
示例7: NewClient
// NewClient creates a new Google Stackdriver Trace client.
func NewClient(ctx context.Context, projectID string, opts ...cloud.ClientOption) (*Client, error) {
o := []cloud.ClientOption{
cloud.WithScopes(cloudPlatformScope),
cloud.WithUserAgent(userAgent),
}
o = append(o, opts...)
hc, basePath, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("creating HTTP client for Google Stackdriver Trace API: %v", err)
}
apiService, err := api.New(hc)
if err != nil {
return nil, fmt.Errorf("creating Google Stackdriver Trace API client: %v", err)
}
if basePath != "" {
// An option set a basepath, so override api.New's default.
apiService.BasePath = basePath
}
return &Client{
service: apiService,
projectID: projectID,
}, nil
}