github.com/xmlking/toolkit/broker/pubsub@v0.3.4/options.go (about) 1 package broker 2 3 import ( 4 "context" 5 6 "google.golang.org/api/option" 7 ) 8 9 // https://github.com/cloudevents/sdk-go/blob/master/protocol/pubsub/v2/options.go 10 11 type Option func(*Options) 12 13 type Options struct { 14 Name string 15 ClientOptions []option.ClientOption 16 ProjectID string 17 18 // Handler executed when error happens in broker message 19 // processing 20 ErrorHandler Handler 21 22 Context context.Context 23 } 24 25 // Name of the service 26 func Name(n string) Option { 27 return func(o *Options) { 28 o.Name = n 29 } 30 } 31 32 // ClientOption is a broker Option which allows google pubsub client options to be 33 // set for the client 34 func ClientOption(c ...option.ClientOption) Option { 35 return func(o *Options) { 36 o.ClientOptions = c 37 } 38 } 39 40 // ProjectID provides an option which sets the google project id 41 func ProjectID(id string) Option { 42 return func(o *Options) { 43 o.ProjectID = id 44 } 45 } 46 47 // ErrorHandler will catch all broker errors that cant be handled 48 // in normal way, for example Codec errors 49 func ErrorHandler(h Handler) Option { 50 return func(o *Options) { 51 o.ErrorHandler = h 52 } 53 } 54 55 // Context appContext to trigger terminate signal 56 func Context(ctx context.Context) Option { 57 return func(o *Options) { 58 o.Context = ctx 59 } 60 }