-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
70 lines (60 loc) · 2.42 KB
/
options.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package pb
import (
"cloud.google.com/go/pubsub"
"google.golang.org/api/option"
)
// PubSubOptions provides a way to configure the PubSub client with various
// options such as the project ID, client options, and publish and receive settings.
type PubSubOptions struct {
AutoOriginatedAt bool
ProjectID string
ClientOptions []option.ClientOption
PublishSettings pubsub.PublishSettings
ReceiveSettings pubsub.ReceiveSettings
}
// Options returns a new PubSubOptions struct with the provided project ID and
// client options. The AutoOriginatedAt field is set to true by default.
// Any ClientOptions provided are passed directly through to the underlying
// pubsub.Client when calling the NewPubSub function.
func Options(pID string, opts ...option.ClientOption) *PubSubOptions {
return &PubSubOptions{
AutoOriginatedAt: true,
ProjectID: pID,
ClientOptions: opts,
}
}
// SetAutoOriginatedAt sets the AutoOriginatedAt field on the PubSubOptions struct
// to the provided value and returns the modified PubSubOptions struct. If true,
// the OriginatedAt attribute will be set to the current time if it is not already
// set for all messages published.
func (o *PubSubOptions) SetAutoOriginatedAt(auto bool) *PubSubOptions {
o.AutoOriginatedAt = auto
return o
}
// SetProjectID sets the ProjectID field on the PubSubOptions struct to the provided
// value and returns the modified PubSubOptions struct.
func (o *PubSubOptions) SetProjectID(pID string) *PubSubOptions {
o.ProjectID = pID
return o
}
// SetClientOptions sets the ClientOptions field on the PubSubOptions struct to the
// provided options and returns the modified PubSubOptions struct.
func (o *PubSubOptions) SetClientOptions(opts ...option.ClientOption) *PubSubOptions {
if o.ClientOptions == nil {
o.ClientOptions = []option.ClientOption{}
}
o.ClientOptions = append(o.ClientOptions, opts...)
return o
}
// SetPublishSettings sets the PublishSettings field on the PubSubOptions struct to
// the provided settings and returns the modified PubSubOptions struct.
func (o *PubSubOptions) SetPublishSettings(s pubsub.PublishSettings) *PubSubOptions {
o.PublishSettings = s
return o
}
// SetReceiveSettings sets the ReceiveSettings field on the PubSubOptions struct to
// the provided settings and returns the modified PubSubOptions struct.
func (o *PubSubOptions) SetReceiveSettings(s pubsub.ReceiveSettings) *PubSubOptions {
o.ReceiveSettings = s
return o
}