-
Notifications
You must be signed in to change notification settings - Fork 1
/
option.go
57 lines (48 loc) · 1.31 KB
/
option.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
package cloudpubsub
import (
"cloud.google.com/go/pubsub"
"google.golang.org/api/option"
)
// Config represents publisher configuration.
type Config struct {
ClientOpts []option.ClientOption
PublishSettingsFunc func(*pubsub.PublishSettings)
TopicConfig *pubsub.TopicConfigToUpdate
CreateTopic bool
DeleteTopic bool
}
func (c *Config) apply(opts []Option) {
for _, f := range opts {
f(c)
}
}
// Option is publisher Option
type Option func(*Config)
// WithClientOptions returns an Option that set option.ClientOption implementation(s).
func WithClientOptions(opts ...option.ClientOption) Option {
return func(c *Config) {
c.ClientOpts = append(c.ClientOpts, opts...)
}
}
// WithPublishSettings returns an Option that set pubsub.PublishSettings to the pubsub.Topic.
func WithPublishSettings(f func(*pubsub.PublishSettings)) Option {
return func(c *Config) {
c.PublishSettingsFunc = f
}
}
// WithUpdateTopicConfig returns an Option that update configuration for pubsub.Topic.
func WithUpdateTopicConfig(cfg pubsub.TopicConfigToUpdate) Option {
return func(c *Config) {
c.TopicConfig = &cfg
}
}
func WithCreateTopicIfNeeded() Option {
return func(c *Config) {
c.CreateTopic = true
}
}
func WithDeleteTopicOnClose() Option {
return func(c *Config) {
c.DeleteTopic = true
}
}