-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
40 lines (32 loc) · 1.08 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package pubsub
import (
"context"
"cloud.google.com/go/pubsub"
"google.golang.org/api/option"
)
// NewClient returns a new bigquery client with default options.
func NewClient(ctx context.Context) (*pubsub.Client, error) {
opt, err := NewOptions()
if err != nil {
return nil, err
}
return NewClientWithOptions(ctx, opt)
}
// NewClientWithConfigPath returns a new bigquery client with options from config path.
func NewClientWithConfigPath(ctx context.Context, path string) (*pubsub.Client, error) {
options, err := NewOptionsWithPath(path)
if err != nil {
return nil, err
}
return NewClientWithOptions(ctx, options)
}
// NewClientWithOptions returns a new bigquery client with options.
func NewClientWithOptions(ctx context.Context, options *Options) (*pubsub.Client, error) {
var opts []option.ClientOption
if options.Credentials.JSON != "" {
opts = append(opts, option.WithCredentialsJSON([]byte(options.Credentials.JSON)))
} else {
opts = append(opts, option.WithCredentialsFile(options.Credentials.File))
}
return pubsub.NewClient(ctx, options.ProjectID, opts...)
}