aboutsummaryrefslogtreecommitdiff
path: root/vendor/google.golang.org/cloud/option.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/cloud/option.go')
-rw-r--r--vendor/google.golang.org/cloud/option.go75
1 files changed, 21 insertions, 54 deletions
diff --git a/vendor/google.golang.org/cloud/option.go b/vendor/google.golang.org/cloud/option.go
index 8a443b4..4788c67 100644
--- a/vendor/google.golang.org/cloud/option.go
+++ b/vendor/google.golang.org/cloud/option.go
@@ -18,97 +18,64 @@ import (
"net/http"
"golang.org/x/oauth2"
- "google.golang.org/cloud/internal/opts"
+ "google.golang.org/api/option"
"google.golang.org/grpc"
)
// ClientOption is used when construct clients for each cloud service.
type ClientOption interface {
- // Resolve configures the given DialOpts for this option.
- Resolve(*opts.DialOpt)
+ // Resolve returns the equivalent option from the
+ // google.golang.org/api/option package.
+ Resolve() option.ClientOption
}
-// WithTokenSource returns a ClientOption that specifies an OAuth2 token
-// source to be used as the basis for authentication.
-func WithTokenSource(s oauth2.TokenSource) ClientOption {
- return withTokenSource{s}
+type wrapOpt struct {
+ o option.ClientOption
}
-type withTokenSource struct{ ts oauth2.TokenSource }
+func (w wrapOpt) Resolve() option.ClientOption {
+ return w.o
+}
-func (w withTokenSource) Resolve(o *opts.DialOpt) {
- o.TokenSource = w.ts
+// WithTokenSource returns a ClientOption that specifies an OAuth2 token
+// source to be used as the basis for authentication.
+func WithTokenSource(s oauth2.TokenSource) ClientOption {
+ return wrapOpt{option.WithTokenSource(s)}
}
// WithEndpoint returns a ClientOption that overrides the default endpoint
// to be used for a service.
func WithEndpoint(url string) ClientOption {
- return withEndpoint(url)
-}
-
-type withEndpoint string
-
-func (w withEndpoint) Resolve(o *opts.DialOpt) {
- o.Endpoint = string(w)
+ return wrapOpt{option.WithEndpoint(url)}
}
// WithScopes returns a ClientOption that overrides the default OAuth2 scopes
// to be used for a service.
func WithScopes(scope ...string) ClientOption {
- return withScopes(scope)
-}
-
-type withScopes []string
-
-func (w withScopes) Resolve(o *opts.DialOpt) {
- s := make([]string, len(w))
- copy(s, w)
- o.Scopes = s
+ return wrapOpt{option.WithScopes(scope...)}
}
// WithUserAgent returns a ClientOption that sets the User-Agent.
func WithUserAgent(ua string) ClientOption {
- return withUA(ua)
+ return wrapOpt{option.WithUserAgent(ua)}
}
-type withUA string
-
-func (w withUA) Resolve(o *opts.DialOpt) { o.UserAgent = string(w) }
-
// WithBaseHTTP returns a ClientOption that specifies the HTTP client to
// use as the basis of communications. This option may only be used with
// services that support HTTP as their communication transport.
func WithBaseHTTP(client *http.Client) ClientOption {
- return withBaseHTTP{client}
-}
-
-type withBaseHTTP struct{ client *http.Client }
-
-func (w withBaseHTTP) Resolve(o *opts.DialOpt) {
- o.HTTPClient = w.client
+ return wrapOpt{option.WithHTTPClient(client)}
}
// WithBaseGRPC returns a ClientOption that specifies the gRPC client
// connection to use as the basis of communications. This option many only be
// used with services that support gRPC as their communication transport.
-func WithBaseGRPC(client *grpc.ClientConn) ClientOption {
- return withBaseGRPC{client}
-}
-
-type withBaseGRPC struct{ client *grpc.ClientConn }
-
-func (w withBaseGRPC) Resolve(o *opts.DialOpt) {
- o.GRPCClient = w.client
+func WithBaseGRPC(conn *grpc.ClientConn) ClientOption {
+ return wrapOpt{option.WithGRPCConn(conn)}
}
// WithGRPCDialOption returns a ClientOption that appends a new grpc.DialOption
// to an underlying gRPC dial. It does not work with WithBaseGRPC.
-func WithGRPCDialOption(opt grpc.DialOption) ClientOption {
- return withGRPCDialOption{opt}
-}
-
-type withGRPCDialOption struct{ opt grpc.DialOption }
-
-func (w withGRPCDialOption) Resolve(o *opts.DialOpt) {
- o.GRPCDialOpts = append(o.GRPCDialOpts, w.opt)
+func WithGRPCDialOption(o grpc.DialOption) ClientOption {
+ return wrapOpt{option.WithGRPCDialOption(o)}
}