本文整理汇总了Golang中google/golang.org/cloud.WithContext函数的典型用法代码示例。如果您正苦于以下问题:Golang WithContext函数的具体用法?Golang WithContext怎么用?Golang WithContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithContext函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: pubsubContext
func pubsubContext(ctx context.Context, projectID string) (context.Context, error) {
httpClient, err := google.DefaultClient(ctx, pubsub.ScopePubSub)
if err != nil {
return nil, err
}
return cloud.WithContext(ctx, projectID, httpClient), nil
}
示例2: newPubSubService
func newPubSubService(ctx context.Context, config pubsubConfig, client *http.Client) (pubSubService, error) {
if config.project == "" {
return nil, errors.New("pubsub: you must supply a project")
}
return &pubSubServiceImpl{
ctx: cloud.WithContext(ctx, config.project, client),
}, nil
}
示例3: cloudContext
func cloudContext(projectID string) (context.Context, error) {
ctx := context.Background()
httpClient, err := google.DefaultClient(ctx, storage.ScopeFullControl, pubsub.ScopePubSub)
if err != nil {
return nil, err
}
return cloud.WithContext(ctx, projectID, httpClient), nil
}
示例4: handleFunc
func handleFunc(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
c.Infof("env: %v", os.Environ())
client, err := serviceaccount.NewClient(c, "https://www.googleapis.com/auth/devstorage.read_write")
c.Infof("client=%+v err=%+v", client, err)
cc := cloud.WithContext(context.Background(), appengine.AppID(c), client)
bucket, err := storage.BucketInfo(cc, appengine.AppID(c)+".appspot.com")
c.Infof("bucket=%+v err=%+v", bucket, err)
}
示例5: Context
// Context returns an cloud.Context based on the receiver Config.
func (c *Config) Context(ctx context.Context) (context.Context, error) {
if c.ProjectID == "" {
return nil, errors.New("oauth2 configuration missing project ID")
}
cl, err := c.Client(ctx)
if err != nil {
return nil, err
}
return cloud.WithContext(ctx, c.ProjectID, cl), nil
}
示例6: Generate
func (cfg *AppengineStoreConfig) Generate(c context.Context) files.FileStore {
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
ctx := cloud.WithContext(c, appengine.AppID(c), hc)
return &AppengineStore{cfg, ctx}
}
示例7: cloudAuthContext
// Get an auth context for logging RPC.
func cloudAuthContext(r *http.Request) (context.Context, error) {
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, logging.Scope),
Base: &urlfetch.Transport{Context: c},
},
}
return cloud.WithContext(c, appengine.AppID(c), hc), nil
}
示例8: cloudAuthContext
func cloudAuthContext(r *http.Request) (context.Context, error) {
c := appengine.NewContext(r)
hc := &http.Client{
Transport: &oauth2.Transport{
Source: google.AppEngineTokenSource(c, storage.ScopeFullControl),
Base: &urlfetch.Transport{Context: c},
},
}
return cloud.WithContext(c, "rule110-go", hc), nil
}
示例9: context
func (d *driver) context(context ctx.Context) context.Context {
return cloud.WithContext(context, dummyProjectID, d.client)
}
示例10: CloudContext
func CloudContext(parent context.Context) context.Context {
if parent == nil {
return cloud.NewContext(projID, cloudClient)
}
return cloud.WithContext(parent, projID, cloudClient)
}
示例11: context
func (this *SalesforceOpportunityEvents) context(ctx context.Context) context.Context {
return cloud.WithContext(ctx, this.projectID, this.conf.Client(oauth2.NoContext))
}