Files
go-micro/cmd/options.go
T

245 lines
5.1 KiB
Go
Raw Normal View History

2016-01-01 01:16:21 +00:00
package cmd
import (
2018-03-03 11:53:52 +00:00
"context"
2021-09-24 09:08:39 +01:00
2024-06-04 21:40:43 +01:00
"go-micro.dev/v5/auth"
"go-micro.dev/v5/broker"
"go-micro.dev/v5/cache"
"go-micro.dev/v5/client"
"go-micro.dev/v5/config"
"go-micro.dev/v5/debug/profile"
"go-micro.dev/v5/debug/trace"
2025-06-18 17:12:02 +01:00
"go-micro.dev/v5/events"
2024-06-04 21:40:43 +01:00
"go-micro.dev/v5/registry"
"go-micro.dev/v5/selector"
"go-micro.dev/v5/server"
"go-micro.dev/v5/store"
"go-micro.dev/v5/transport"
2016-01-01 01:16:21 +00:00
)
type Options struct {
2023-04-26 00:16:34 +00:00
// Other options for implementations of the interface
// can be stored in a context
2025-05-20 13:24:06 -04:00
Context context.Context
Auth *auth.Auth
Selector *selector.Selector
DebugProfile *profile.Profile
2023-04-26 00:16:34 +00:00
Registry *registry.Registry
2025-05-20 13:24:06 -04:00
Brokers map[string]func(...broker.Option) broker.Broker
Transport *transport.Transport
Cache *cache.Cache
Config *config.Config
Client *client.Client
Server *server.Server
Caches map[string]func(...cache.Option) cache.Cache
Tracer *trace.Tracer
DebugProfiles map[string]func(...profile.Option) profile.Profile
2016-01-02 00:38:57 +00:00
2023-04-26 00:16:34 +00:00
// We need pointers to things so we can swap them out if needed.
Broker *broker.Broker
Auths map[string]func(...auth.Option) auth.Auth
Store *store.Store
2025-06-18 17:12:02 +01:00
Stream *events.Stream
2020-03-12 18:47:40 +00:00
Configs map[string]func(...config.Option) (config.Config, error)
2016-11-18 17:29:26 +00:00
Clients map[string]func(...client.Option) client.Client
2016-03-15 22:20:21 +00:00
Registries map[string]func(...registry.Option) registry.Registry
2016-01-01 01:16:21 +00:00
Selectors map[string]func(...selector.Option) selector.Selector
2016-11-18 17:29:26 +00:00
Servers map[string]func(...server.Option) server.Server
2016-03-15 22:25:32 +00:00
Transports map[string]func(...transport.Option) transport.Transport
2020-01-06 17:44:32 +00:00
Stores map[string]func(...store.Option) store.Store
2025-06-18 17:12:02 +01:00
Streams map[string]func(...events.Option) events.Stream
2020-01-29 15:45:11 +00:00
Tracers map[string]func(...trace.Option) trace.Tracer
2023-04-26 00:16:34 +00:00
Version string
2023-04-26 00:16:34 +00:00
// For the Command Line itself
Name string
Description string
2016-01-01 01:16:21 +00:00
}
2022-09-30 16:27:07 +02:00
// Command line Name.
2016-01-01 01:16:21 +00:00
func Name(n string) Option {
return func(o *Options) {
o.Name = n
}
}
2022-09-30 16:27:07 +02:00
// Command line Description.
2016-01-01 01:16:21 +00:00
func Description(d string) Option {
return func(o *Options) {
o.Description = d
}
}
2022-09-30 16:27:07 +02:00
// Command line Version.
2016-01-01 01:16:21 +00:00
func Version(v string) Option {
return func(o *Options) {
o.Version = v
}
}
2016-01-02 00:38:57 +00:00
func Broker(b *broker.Broker) Option {
return func(o *Options) {
o.Broker = b
}
}
2021-08-31 16:31:16 +02:00
func Cache(c *cache.Cache) Option {
return func(o *Options) {
o.Cache = c
}
}
2020-03-12 18:47:40 +00:00
func Config(c *config.Config) Option {
return func(o *Options) {
o.Config = c
}
}
2016-01-02 00:38:57 +00:00
func Selector(s *selector.Selector) Option {
return func(o *Options) {
o.Selector = s
}
}
func Registry(r *registry.Registry) Option {
return func(o *Options) {
o.Registry = r
}
}
func Transport(t *transport.Transport) Option {
return func(o *Options) {
o.Transport = t
}
}
func Client(c *client.Client) Option {
return func(o *Options) {
o.Client = c
}
}
func Server(s *server.Server) Option {
return func(o *Options) {
o.Server = s
}
}
2020-05-01 18:05:09 +01:00
func Store(s *store.Store) Option {
return func(o *Options) {
o.Store = s
}
}
2025-06-18 17:12:02 +01:00
func Stream(s *events.Stream) Option {
return func(o *Options) {
o.Stream = s
}
}
2020-01-29 15:45:11 +00:00
func Tracer(t *trace.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
2020-02-03 08:16:02 +00:00
func Auth(a *auth.Auth) Option {
return func(o *Options) {
o.Auth = a
}
}
func Profile(p *profile.Profile) Option {
return func(o *Options) {
2025-05-20 13:24:06 -04:00
o.DebugProfile = p
}
}
2022-09-30 16:27:07 +02:00
// New broker func.
2016-03-15 22:12:28 +00:00
func NewBroker(name string, b func(...broker.Option) broker.Broker) Option {
2016-01-01 01:16:21 +00:00
return func(o *Options) {
o.Brokers[name] = b
}
}
2025-06-18 17:12:02 +01:00
// New stream func.
func NewStream(name string, b func(...events.Option) events.Stream) Option {
return func(o *Options) {
o.Streams[name] = b
}
}
2022-09-30 16:27:07 +02:00
// New cache func.
2021-08-31 16:31:16 +02:00
func NewCache(name string, c func(...cache.Option) cache.Cache) Option {
return func(o *Options) {
o.Caches[name] = c
}
}
2022-09-30 16:27:07 +02:00
// New client func.
2016-11-18 17:29:26 +00:00
func NewClient(name string, b func(...client.Option) client.Client) Option {
return func(o *Options) {
o.Clients[name] = b
}
}
2022-09-30 16:27:07 +02:00
// New registry func.
2016-03-15 22:20:21 +00:00
func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option {
2016-01-01 01:16:21 +00:00
return func(o *Options) {
o.Registries[name] = r
}
}
2022-09-30 16:27:07 +02:00
// New selector func.
2016-01-02 00:38:57 +00:00
func NewSelector(name string, s func(...selector.Option) selector.Selector) Option {
2016-01-01 01:16:21 +00:00
return func(o *Options) {
o.Selectors[name] = s
}
}
2022-09-30 16:27:07 +02:00
// New server func.
2016-11-18 17:29:26 +00:00
func NewServer(name string, s func(...server.Option) server.Server) Option {
return func(o *Options) {
o.Servers[name] = s
}
}
2022-09-30 16:27:07 +02:00
// New transport func.
2016-03-15 22:25:32 +00:00
func NewTransport(name string, t func(...transport.Option) transport.Transport) Option {
2016-01-01 01:16:21 +00:00
return func(o *Options) {
o.Transports[name] = t
}
}
2022-09-30 16:27:07 +02:00
// New tracer func.
2020-01-29 15:45:11 +00:00
func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option {
return func(o *Options) {
o.Tracers[name] = t
}
}
2020-02-03 08:16:02 +00:00
2022-09-30 16:27:07 +02:00
// New auth func.
2020-02-03 08:16:02 +00:00
func NewAuth(name string, t func(...auth.Option) auth.Auth) Option {
return func(o *Options) {
o.Auths[name] = t
}
}
2022-09-30 16:27:07 +02:00
// New config func.
2021-09-24 09:08:39 +01:00
func NewConfig(name string, t func(...config.Option) (config.Config, error)) Option {
return func(o *Options) {
o.Configs[name] = t
}
}
2022-09-30 16:27:07 +02:00
// New profile func.
func NewProfile(name string, t func(...profile.Option) profile.Profile) Option {
return func(o *Options) {
2025-05-20 13:24:06 -04:00
o.DebugProfiles[name] = t
}
2021-09-19 17:22:28 +01:00
}