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