gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/runtime/options.go (about) 1 package runtime 2 3 import ( 4 "io" 5 ) 6 7 type Option func(o *Options) 8 9 // Options configure runtime 10 type Options struct { 11 // Notifier for updates 12 Notifier Notifier 13 // Service type to manage 14 Type string 15 } 16 17 // WithNotifier specifies a notifier for updates 18 func WithNotifier(n Notifier) Option { 19 return func(o *Options) { 20 o.Notifier = n 21 } 22 } 23 24 // WithType sets the service type to manage 25 func WithType(t string) Option { 26 return func(o *Options) { 27 o.Type = t 28 } 29 } 30 31 type CreateOption func(o *CreateOptions) 32 33 type ReadOption func(o *ReadOptions) 34 35 // CreateOptions configure runtime services 36 type CreateOptions struct { 37 // command to execute including args 38 Command []string 39 // Environment to configure 40 Env []string 41 // Log output 42 Output io.Writer 43 // Type of service to create 44 Type string 45 } 46 47 // ReadOptions queries runtime services 48 type ReadOptions struct { 49 // Service name 50 Service string 51 // Version queries services with given version 52 Version string 53 // Type of service 54 Type string 55 } 56 57 // WithCommand specifies the command to execute 58 func WithCommand(args ...string) CreateOption { 59 return func(o *CreateOptions) { 60 // set command 61 o.Command = args 62 } 63 } 64 65 // WithEnv sets the created service environment 66 func WithEnv(env []string) CreateOption { 67 return func(o *CreateOptions) { 68 o.Env = env 69 } 70 } 71 72 // WithOutput sets the arg output 73 func WithOutput(out io.Writer) CreateOption { 74 return func(o *CreateOptions) { 75 o.Output = out 76 } 77 } 78 79 // ReadService returns services with the given name 80 func ReadService(service string) ReadOption { 81 return func(o *ReadOptions) { 82 o.Service = service 83 } 84 } 85 86 // WithVersion confifgures service version 87 func ReadVersion(version string) ReadOption { 88 return func(o *ReadOptions) { 89 o.Version = version 90 } 91 } 92 93 // ReadType returns services of the given type 94 func ReadType(t string) ReadOption { 95 return func(o *ReadOptions) { 96 o.Type = t 97 } 98 }