gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/registry/options.go (about) 1 package registry 2 3 import ( 4 "context" 5 "crypto/tls" 6 "time" 7 ) 8 9 type Options struct { 10 Addrs []string 11 Timeout time.Duration 12 Secure bool 13 TLSConfig *tls.Config 14 // Other options for implementations of the interface 15 // can be stored in a context 16 Context context.Context 17 } 18 19 type RegisterOptions struct { 20 TTL time.Duration 21 // Other options for implementations of the interface 22 // can be stored in a context 23 Context context.Context 24 } 25 26 type WatchOptions struct { 27 // Specify a service to watch 28 // If blank, the watch is for all services 29 Service string 30 // Other options for implementations of the interface 31 // can be stored in a context 32 Context context.Context 33 } 34 35 // Addrs is the registry addresses to use 36 func Addrs(addrs ...string) Option { 37 return func(o *Options) { 38 o.Addrs = addrs 39 } 40 } 41 42 func Timeout(t time.Duration) Option { 43 return func(o *Options) { 44 o.Timeout = t 45 } 46 } 47 48 // Secure communication with the registry 49 func Secure(b bool) Option { 50 return func(o *Options) { 51 o.Secure = b 52 } 53 } 54 55 // Specify TLS Config 56 func TLSConfig(t *tls.Config) Option { 57 return func(o *Options) { 58 o.TLSConfig = t 59 } 60 } 61 62 func RegisterTTL(t time.Duration) RegisterOption { 63 return func(o *RegisterOptions) { 64 o.TTL = t 65 } 66 } 67 68 // Watch a service 69 func WatchService(name string) WatchOption { 70 return func(o *WatchOptions) { 71 o.Service = name 72 } 73 }