go-micro.dev/v5@v5.12.0/cmd/options.go (about) 1 package cmd 2 3 import ( 4 "context" 5 6 "go-micro.dev/v5/auth" 7 "go-micro.dev/v5/broker" 8 "go-micro.dev/v5/cache" 9 "go-micro.dev/v5/client" 10 "go-micro.dev/v5/config" 11 "go-micro.dev/v5/debug/profile" 12 "go-micro.dev/v5/debug/trace" 13 "go-micro.dev/v5/events" 14 "go-micro.dev/v5/registry" 15 "go-micro.dev/v5/selector" 16 "go-micro.dev/v5/server" 17 "go-micro.dev/v5/store" 18 "go-micro.dev/v5/transport" 19 ) 20 21 type Options struct { 22 23 // Other options for implementations of the interface 24 // can be stored in a context 25 Context context.Context 26 Auth *auth.Auth 27 Selector *selector.Selector 28 DebugProfile *profile.Profile 29 30 Registry *registry.Registry 31 32 Brokers map[string]func(...broker.Option) broker.Broker 33 Transport *transport.Transport 34 Cache *cache.Cache 35 Config *config.Config 36 Client *client.Client 37 Server *server.Server 38 Caches map[string]func(...cache.Option) cache.Cache 39 Tracer *trace.Tracer 40 DebugProfiles map[string]func(...profile.Option) profile.Profile 41 42 // We need pointers to things so we can swap them out if needed. 43 Broker *broker.Broker 44 Auths map[string]func(...auth.Option) auth.Auth 45 Store *store.Store 46 Stream *events.Stream 47 Configs map[string]func(...config.Option) (config.Config, error) 48 Clients map[string]func(...client.Option) client.Client 49 Registries map[string]func(...registry.Option) registry.Registry 50 Selectors map[string]func(...selector.Option) selector.Selector 51 Servers map[string]func(...server.Option) server.Server 52 Transports map[string]func(...transport.Option) transport.Transport 53 Stores map[string]func(...store.Option) store.Store 54 Streams map[string]func(...events.Option) events.Stream 55 Tracers map[string]func(...trace.Option) trace.Tracer 56 Version string 57 58 // For the Command Line itself 59 Name string 60 Description string 61 } 62 63 // Command line Name. 64 func Name(n string) Option { 65 return func(o *Options) { 66 o.Name = n 67 } 68 } 69 70 // Command line Description. 71 func Description(d string) Option { 72 return func(o *Options) { 73 o.Description = d 74 } 75 } 76 77 // Command line Version. 78 func Version(v string) Option { 79 return func(o *Options) { 80 o.Version = v 81 } 82 } 83 84 func Broker(b *broker.Broker) Option { 85 return func(o *Options) { 86 o.Broker = b 87 broker.DefaultBroker = *b 88 } 89 } 90 91 func Cache(c *cache.Cache) Option { 92 return func(o *Options) { 93 o.Cache = c 94 cache.DefaultCache = *c 95 } 96 } 97 98 func Config(c *config.Config) Option { 99 return func(o *Options) { 100 o.Config = c 101 config.DefaultConfig = *c 102 } 103 } 104 105 func Selector(s *selector.Selector) Option { 106 return func(o *Options) { 107 o.Selector = s 108 selector.DefaultSelector = *s 109 } 110 } 111 112 func Registry(r *registry.Registry) Option { 113 return func(o *Options) { 114 o.Registry = r 115 registry.DefaultRegistry = *r 116 } 117 } 118 119 func Transport(t *transport.Transport) Option { 120 return func(o *Options) { 121 o.Transport = t 122 transport.DefaultTransport = *t 123 } 124 } 125 126 func Client(c *client.Client) Option { 127 return func(o *Options) { 128 o.Client = c 129 client.DefaultClient = *c 130 } 131 } 132 133 func Server(s *server.Server) Option { 134 return func(o *Options) { 135 o.Server = s 136 server.DefaultServer = *s 137 } 138 } 139 140 func Store(s *store.Store) Option { 141 return func(o *Options) { 142 o.Store = s 143 store.DefaultStore = *s 144 } 145 } 146 147 func Stream(s *events.Stream) Option { 148 return func(o *Options) { 149 o.Stream = s 150 events.DefaultStream = *s 151 } 152 } 153 154 func Tracer(t *trace.Tracer) Option { 155 return func(o *Options) { 156 o.Tracer = t 157 trace.DefaultTracer = *t 158 } 159 } 160 161 func Auth(a *auth.Auth) Option { 162 return func(o *Options) { 163 o.Auth = a 164 auth.DefaultAuth = *a 165 } 166 } 167 168 func Profile(p *profile.Profile) Option { 169 return func(o *Options) { 170 o.DebugProfile = p 171 profile.DefaultProfile = *p 172 } 173 } 174 175 // New broker func. 176 func NewBroker(name string, b func(...broker.Option) broker.Broker) Option { 177 return func(o *Options) { 178 o.Brokers[name] = b 179 } 180 } 181 182 // New stream func. 183 func NewStream(name string, b func(...events.Option) events.Stream) Option { 184 return func(o *Options) { 185 o.Streams[name] = b 186 } 187 } 188 189 // New cache func. 190 func NewCache(name string, c func(...cache.Option) cache.Cache) Option { 191 return func(o *Options) { 192 o.Caches[name] = c 193 } 194 } 195 196 // New client func. 197 func NewClient(name string, b func(...client.Option) client.Client) Option { 198 return func(o *Options) { 199 o.Clients[name] = b 200 } 201 } 202 203 // New registry func. 204 func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option { 205 return func(o *Options) { 206 o.Registries[name] = r 207 } 208 } 209 210 // New selector func. 211 func NewSelector(name string, s func(...selector.Option) selector.Selector) Option { 212 return func(o *Options) { 213 o.Selectors[name] = s 214 } 215 } 216 217 // New server func. 218 func NewServer(name string, s func(...server.Option) server.Server) Option { 219 return func(o *Options) { 220 o.Servers[name] = s 221 } 222 } 223 224 // New transport func. 225 func NewTransport(name string, t func(...transport.Option) transport.Transport) Option { 226 return func(o *Options) { 227 o.Transports[name] = t 228 } 229 } 230 231 // New tracer func. 232 func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option { 233 return func(o *Options) { 234 o.Tracers[name] = t 235 } 236 } 237 238 // New auth func. 239 func NewAuth(name string, t func(...auth.Option) auth.Auth) Option { 240 return func(o *Options) { 241 o.Auths[name] = t 242 } 243 } 244 245 // New config func. 246 func NewConfig(name string, t func(...config.Option) (config.Config, error)) Option { 247 return func(o *Options) { 248 o.Configs[name] = t 249 } 250 } 251 252 // New profile func. 253 func NewProfile(name string, t func(...profile.Option) profile.Profile) Option { 254 return func(o *Options) { 255 o.DebugProfiles[name] = t 256 } 257 }