本文整理汇总了Golang中google/golang.org/api/option.WithScopes函数的典型用法代码示例。如果您正苦于以下问题:Golang WithScopes函数的具体用法?Golang WithScopes怎么用?Golang WithScopes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithScopes函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewClient
// NewClient creates a new PubSub client.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
var o []option.ClientOption
// Environment variables for gcloud emulator:
// https://option.google.com/sdk/gcloud/reference/beta/emulators/pubsub/
if addr := os.Getenv("PUBSUB_EMULATOR_HOST"); addr != "" {
o = []option.ClientOption{
option.WithEndpoint("http://" + addr + "/"),
option.WithHTTPClient(http.DefaultClient),
}
} else {
o = []option.ClientOption{
option.WithEndpoint(prodAddr),
option.WithScopes(raw.PubsubScope, raw.CloudPlatformScope),
option.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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:35,代码来源:pubsub.go
示例2: NewClient
// NewClient creates a new Google Container Engine client.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
o := []option.ClientOption{
option.WithEndpoint(prodAddr),
option.WithScopes(raw.CloudPlatformScope),
option.WithUserAgent(userAgent),
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
svc, err := raw.New(httpClient)
if err != nil {
return nil, fmt.Errorf("constructing container client: %v", err)
}
svc.BasePath = endpoint
c := &Client{
projectID: projectID,
svc: svc,
}
return c, nil
}
开发者ID:camlistore,项目名称:camlistore,代码行数:26,代码来源:container.go
示例3: 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 ...option.ClientOption) (*Client, error) {
httpClient, endpoint, err := transport.NewHTTPClient(ctx, append([]option.ClientOption{
option.WithEndpoint(prodAddr),
option.WithScopes(Scope),
option.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
}
开发者ID:IanLewis,项目名称:weathersensors,代码行数:33,代码来源:logging.go
示例4: defaultClientOptions
func defaultClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("speech.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
),
}
}
开发者ID:trythings,项目名称:trythings,代码行数:8,代码来源:speech_client.go
示例5: defaultImageAnnotatorClientOptions
func defaultImageAnnotatorClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("vision.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
),
}
}
开发者ID:trythings,项目名称:trythings,代码行数:8,代码来源:image_annotator_client.go
示例6: defaultReportErrorsClientOptions
func defaultReportErrorsClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("clouderrorreporting.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
),
}
}
开发者ID:trythings,项目名称:trythings,代码行数:8,代码来源:report_errors_client.go
示例7: defaultController2ClientOptions
func defaultController2ClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("clouddebugger.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud_debugger",
),
}
}
开发者ID:trythings,项目名称:trythings,代码行数:9,代码来源:controller2_client.go
示例8: defaultSubscriberClientOptions
func defaultSubscriberClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("pubsub.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/pubsub",
),
}
}
开发者ID:GoogleCloudPlatform,项目名称:gcloud-golang,代码行数:9,代码来源:subscriber_client.go
示例9: defaultClientOptions
func defaultClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("cloudtrace.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/trace.readonly",
),
}
}
开发者ID:trythings,项目名称:trythings,代码行数:10,代码来源:trace_client.go
示例10: defaultMetricClientOptions
func defaultMetricClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("monitoring.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/monitoring",
"https://www.googleapis.com/auth/monitoring.read",
"https://www.googleapis.com/auth/monitoring.write",
),
}
}
开发者ID:trythings,项目名称:trythings,代码行数:11,代码来源:metric_client.go
示例11: defaultClientOptions
func defaultClientOptions() []option.ClientOption {
return []option.ClientOption{
option.WithEndpoint("logging.googleapis.com:443"),
option.WithScopes(
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/cloud-platform.read-only",
"https://www.googleapis.com/auth/logging.admin",
"https://www.googleapis.com/auth/logging.read",
"https://www.googleapis.com/auth/logging.write",
),
}
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:12,代码来源:logging_client.go
示例12: NewClient
// NewClient returns a new logging client associated with the provided project ID.
//
// By default NewClient uses WriteScope. To use a different scope, call
// NewClient using a WithScopes option.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
// Check for '/' in project ID to reserve the ability to support various owning resources,
// in the form "{Collection}/{Name}", for instance "organizations/my-org".
if strings.ContainsRune(projectID, '/') {
return nil, errors.New("logging: project ID contains '/'")
}
opts = append([]option.ClientOption{option.WithEndpoint(prodAddr), option.WithScopes(WriteScope)},
opts...)
lc, err := vkit.NewClient(ctx, opts...)
if err != nil {
return nil, err
}
// TODO(jba): pass along any client options that should be provided to all clients.
sc, err := vkit.NewConfigClient(ctx, option.WithGRPCConn(lc.Connection()))
if err != nil {
return nil, err
}
mc, err := vkit.NewMetricsClient(ctx, option.WithGRPCConn(lc.Connection()))
if err != nil {
return nil, err
}
lc.SetGoogleClientInfo("logging", version)
sc.SetGoogleClientInfo("logging", version)
mc.SetGoogleClientInfo("logging", version)
client := &Client{
lClient: lc,
sClient: sc,
mClient: mc,
projectID: projectID,
errc: make(chan error, defaultErrorCapacity), // create a small buffer for errors
donec: make(chan struct{}),
OnError: func(e error) { log.Printf("logging client: %v", e) },
}
// Call the user's function synchronously, to make life easier for them.
go func() {
for err := range client.errc {
// This reference to OnError is memory-safe if the user sets OnError before
// calling any client methods. The reference happens before the first read from
// client.errc, which happens before the first write to client.errc, which
// happens before any call, which happens before the user sets OnError.
if fn := client.OnError; fn != nil {
fn(err)
} else {
log.Printf("logging (project ID %q): %v", projectID, err)
}
}
}()
return client, nil
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:53,代码来源:logging.go
示例13: NewClient
// NewClient constructs a new Client that can perform Translate operations.
//
// You can find or create API key for your project from the Credentials page of
// the Developers Console (console.developers.google.com).
func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
o := []option.ClientOption{
option.WithEndpoint(prodAddr),
option.WithScopes(Scope),
option.WithUserAgent(userAgent),
}
o = append(o, opts...)
httpClient, endpoint, err := transport.NewHTTPClient(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
rawService, err := raw.New(httpClient)
if err != nil {
return nil, fmt.Errorf("translate client: %v", err)
}
rawService.BasePath = endpoint
return &Client{raw: rawService}, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:22,代码来源:translate.go
示例14: NewClient
// NewClient creates a new Client for a given dataset.
// If the project ID is empty, it is derived from the DATASTORE_PROJECT_ID environment variable.
// If the DATASTORE_EMULATOR_HOST environment variable is set, client will use its value
// to connect to a locally-running datastore emulator.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
var o []option.ClientOption
// Environment variables for gcd emulator:
// https://cloud.google.com/datastore/docs/tools/datastore-emulator
// If the emulator is available, dial it directly (and don't pass any credentials).
if addr := os.Getenv("DATASTORE_EMULATOR_HOST"); addr != "" {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("grpc.Dial: %v", err)
}
o = []option.ClientOption{option.WithGRPCConn(conn)}
} else {
o = []option.ClientOption{
option.WithEndpoint(prodAddr),
option.WithScopes(ScopeDatastore),
option.WithUserAgent(userAgent),
}
}
// Warn if we see the legacy emulator environment variables.
if os.Getenv("DATASTORE_HOST") != "" && os.Getenv("DATASTORE_EMULATOR_HOST") == "" {
log.Print("WARNING: legacy environment variable DATASTORE_HOST is ignored. Use DATASTORE_EMULATOR_HOST instead.")
}
if os.Getenv("DATASTORE_DATASET") != "" && os.Getenv("DATASTORE_PROJECT_ID") == "" {
log.Print("WARNING: legacy environment variable DATASTORE_DATASET is ignored. Use DATASTORE_PROJECT_ID instead.")
}
if projectID == "" {
projectID = os.Getenv("DATASTORE_PROJECT_ID")
}
if projectID == "" {
return nil, errors.New("datastore: missing project/dataset id")
}
o = append(o, opts...)
conn, err := transport.DialGRPC(ctx, o...)
if err != nil {
return nil, fmt.Errorf("dialing: %v", err)
}
return &Client{
conn: conn,
client: newDatastoreClient(conn, projectID),
dataset: projectID,
}, nil
}
开发者ID:GoogleCloudPlatform,项目名称:gcloud-golang,代码行数:47,代码来源:datastore.go
示例15: DefaultClientOptions
// DefaultClientOptions returns the default client options to use for the
// client's gRPC connection.
func DefaultClientOptions(endpoint, scope, userAgent string) ([]option.ClientOption, error) {
var o []option.ClientOption
// Check the environment variables for the bigtable emulator.
// Dial it directly and don't pass any credentials.
if addr := os.Getenv("BIGTABLE_EMULATOR_HOST"); addr != "" {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("emulator grpc.Dial: %v", err)
}
o = []option.ClientOption{option.WithGRPCConn(conn)}
} else {
o = []option.ClientOption{
option.WithEndpoint(endpoint),
option.WithScopes(scope),
option.WithUserAgent(userAgent),
}
}
return o, nil
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:21,代码来源:option.go
示例16: NewClient
// NewClient creates a new Google Stackdriver Trace client.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
o := []option.ClientOption{
option.WithScopes(cloudPlatformScope),
option.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
}
c := &Client{
service: apiService,
projectID: projectID,
}
bundler := bundler.NewBundler((*api.Trace)(nil), func(bundle interface{}) {
traces := bundle.([]*api.Trace)
err := c.upload(traces)
if err != nil {
log.Printf("failed to upload %d traces to the Cloud Trace server.", len(traces))
}
})
bundler.DelayThreshold = 2 * time.Second
bundler.BundleCountThreshold = 100
// We're not measuring bytes here, we're counting traces and spans as one "byte" each.
bundler.BundleByteThreshold = 1000
bundler.BundleByteLimit = 1000
bundler.BufferedByteLimit = 10000
c.bundler = bundler
return c, nil
}
开发者ID:trythings,项目名称:trythings,代码行数:39,代码来源:trace.go
示例17: NewClient
// NewClient creates a new Google Stackdriver Trace client.
func NewClient(ctx context.Context, projectID string, opts ...option.ClientOption) (*Client, error) {
o := []option.ClientOption{
option.WithScopes(cloudPlatformScope),
option.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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:24,代码来源:trace.go
示例18: 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 ...option.ClientOption) (*Client, error) {
o := []option.ClientOption{
option.WithEndpoint(prodAddr),
option.WithScopes(Scope),
option.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
}
开发者ID:rawlingsj,项目名称:gofabric8,代码行数:25,代码来源:bigquery.go
示例19:
ProjectID string // GCP Project ID.
AppModule string // Module name for the debugged program.
AppVersion string // Version number for this module.
SourceContexts []*cd.SourceContext // Description of source.
Verbose bool
ServiceAccountFile string // File containing service account credentials.
}
type serviceInterface interface {
Register(req *cd.RegisterDebuggeeRequest) (*cd.RegisterDebuggeeResponse, error)
Update(debuggeeID, breakpointID string, req *cd.UpdateActiveBreakpointRequest) (*cd.UpdateActiveBreakpointResponse, error)
List(debuggeeID, waitToken string) (*cd.ListActiveBreakpointsResponse, error)
}
var newService = func(serviceAccountFile string) (serviceInterface, error) {
opts := []option.ClientOption{option.WithScopes(cd.CloudDebuggerScope)}
if serviceAccountFile != "" {
opts = append(opts, option.WithServiceAccountFile(serviceAccountFile))
}
httpClient, endpoint, err := transport.NewHTTPClient(context.Background(), opts...)
if err != nil {
return nil, err
}
s, err := cd.New(httpClient)
if err != nil {
return nil, err
}
if endpoint != "" {
s.BasePath = endpoint
}
return &service{s: s}, nil
开发者ID:trythings,项目名称:trythings,代码行数:31,代码来源:client.go
示例20: WithScopes
// WithScopes returns a ClientOption that overrides the default OAuth2 scopes
// to be used for a service.
func WithScopes(scope ...string) ClientOption {
return wrapOpt{option.WithScopes(scope...)}
}
开发者ID:trythings,项目名称:trythings,代码行数:5,代码来源:option.go
注:本文中的google/golang.org/api/option.WithScopes函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论