github.com/godevsig/adaptiveservice@v0.9.23/options.go (about) 1 package adaptiveservice 2 3 type conf struct { 4 lg Logger 5 registryAddr string 6 providerID string 7 scope Scope 8 qsize int 9 } 10 11 func newConf() *conf { 12 return &conf{ 13 lg: LoggerNull{}, 14 scope: ScopeAll, 15 qsize: 128, 16 } 17 } 18 19 // Option is option to be set. 20 type Option func(*conf) 21 22 // WithLogger sets the logger. 23 func WithLogger(lg Logger) Option { 24 return func(c *conf) { 25 c.lg = lg 26 } 27 } 28 29 // WithScope sets the publishing or discovering scope, which is 30 // an ORed value of ScopeProcess, ScopeOS, ScopeLAN or ScopeWAN. 31 // Default is ScopeAll. 32 func WithScope(scope Scope) Option { 33 return func(c *conf) { 34 c.scope = scope 35 } 36 } 37 38 // WithProviderID sets the provider ID which is used to identify service 39 // in the network where there are multiple publisher_service instances 40 // found in the registry. 41 // Provider ID is usually shared by servers in the same network node. 42 func WithProviderID(id string) Option { 43 return func(c *conf) { 44 c.providerID = id 45 } 46 } 47 48 // WithRegistryAddr sets the registry address in format ip:port. 49 func WithRegistryAddr(addr string) Option { 50 return func(c *conf) { 51 c.registryAddr = addr 52 } 53 } 54 55 // WithQsize sets the transport layer message queue size. 56 func WithQsize(size int) Option { 57 return func(c *conf) { 58 c.qsize = size 59 } 60 }