2016-01-01 04:16:21 +03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-03-03 14:53:52 +03:00
|
|
|
"context"
|
|
|
|
|
2020-02-03 11:16:02 +03:00
|
|
|
"github.com/micro/go-micro/v2/auth"
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/broker"
|
|
|
|
"github.com/micro/go-micro/v2/client"
|
2020-03-12 21:13:03 +03:00
|
|
|
"github.com/micro/go-micro/v2/config"
|
2020-02-25 19:42:43 +03:00
|
|
|
"github.com/micro/go-micro/v2/debug/profile"
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/debug/trace"
|
|
|
|
"github.com/micro/go-micro/v2/registry"
|
2020-06-24 13:46:51 +03:00
|
|
|
"github.com/micro/go-micro/v2/router"
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/runtime"
|
2020-07-01 19:06:59 +03:00
|
|
|
"github.com/micro/go-micro/v2/selector"
|
2020-01-30 14:39:00 +03:00
|
|
|
"github.com/micro/go-micro/v2/server"
|
|
|
|
"github.com/micro/go-micro/v2/store"
|
|
|
|
"github.com/micro/go-micro/v2/transport"
|
2016-01-01 04:16:21 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Options struct {
|
2016-01-02 03:38:57 +03:00
|
|
|
// For the Command Line itself
|
2016-01-01 04:16:21 +03:00
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Version string
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// We need pointers to things so we can swap them out if needed.
|
|
|
|
Broker *broker.Broker
|
|
|
|
Registry *registry.Registry
|
|
|
|
Selector *selector.Selector
|
|
|
|
Transport *transport.Transport
|
2020-03-12 21:47:40 +03:00
|
|
|
Config *config.Config
|
2016-01-02 03:38:57 +03:00
|
|
|
Client *client.Client
|
|
|
|
Server *server.Server
|
2020-06-24 13:46:51 +03:00
|
|
|
Router *router.Router
|
2019-11-02 16:25:10 +03:00
|
|
|
Runtime *runtime.Runtime
|
2020-01-06 20:44:32 +03:00
|
|
|
Store *store.Store
|
2020-01-29 18:45:11 +03:00
|
|
|
Tracer *trace.Tracer
|
2020-02-03 11:16:02 +03:00
|
|
|
Auth *auth.Auth
|
2020-02-25 19:42:43 +03:00
|
|
|
Profile *profile.Profile
|
2016-01-02 03:38:57 +03:00
|
|
|
|
2016-03-16 01:12:28 +03:00
|
|
|
Brokers map[string]func(...broker.Option) broker.Broker
|
2020-03-12 21:47:40 +03:00
|
|
|
Configs map[string]func(...config.Option) (config.Config, error)
|
2016-11-18 20:29:26 +03:00
|
|
|
Clients map[string]func(...client.Option) client.Client
|
2016-03-16 01:20:21 +03:00
|
|
|
Registries map[string]func(...registry.Option) registry.Registry
|
2016-01-01 04:16:21 +03:00
|
|
|
Selectors map[string]func(...selector.Option) selector.Selector
|
2016-11-18 20:29:26 +03:00
|
|
|
Servers map[string]func(...server.Option) server.Server
|
2016-03-16 01:25:32 +03:00
|
|
|
Transports map[string]func(...transport.Option) transport.Transport
|
2020-06-24 13:46:51 +03:00
|
|
|
Routers map[string]func(...router.Option) router.Router
|
2019-11-02 16:25:10 +03:00
|
|
|
Runtimes map[string]func(...runtime.Option) runtime.Runtime
|
2020-01-06 20:44:32 +03:00
|
|
|
Stores map[string]func(...store.Option) store.Store
|
2020-01-29 18:45:11 +03:00
|
|
|
Tracers map[string]func(...trace.Option) trace.Tracer
|
2020-02-03 11:16:02 +03:00
|
|
|
Auths map[string]func(...auth.Option) auth.Auth
|
2020-02-25 19:42:43 +03:00
|
|
|
Profiles map[string]func(...profile.Option) profile.Profile
|
2016-01-06 19:25:12 +03:00
|
|
|
|
|
|
|
// Other options for implementations of the interface
|
|
|
|
// can be stored in a context
|
|
|
|
Context context.Context
|
2016-01-01 04:16:21 +03:00
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// Command line Name
|
2016-01-01 04:16:21 +03:00
|
|
|
func Name(n string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Name = n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// Command line Description
|
2016-01-01 04:16:21 +03:00
|
|
|
func Description(d string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Description = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// Command line Version
|
2016-01-01 04:16:21 +03:00
|
|
|
func Version(v string) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Version = v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
func Broker(b *broker.Broker) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Broker = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-12 21:47:40 +03:00
|
|
|
func Config(c *config.Config) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Config = c
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03: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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-24 13:46:51 +03:00
|
|
|
func Router(r *router.Router) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Router = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-11 19:09:28 +03:00
|
|
|
func Runtime(r *runtime.Runtime) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Runtime = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
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 20:05:09 +03:00
|
|
|
func Store(s *store.Store) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Store = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-29 18:45:11 +03:00
|
|
|
func Tracer(t *trace.Tracer) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Tracer = t
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 11:16:02 +03:00
|
|
|
func Auth(a *auth.Auth) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Auth = a
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 19:42:43 +03:00
|
|
|
func Profile(p *profile.Profile) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Profile = p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// New broker func
|
2016-03-16 01:12:28 +03:00
|
|
|
func NewBroker(name string, b func(...broker.Option) broker.Broker) Option {
|
2016-01-01 04:16:21 +03:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Brokers[name] = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:29:26 +03:00
|
|
|
// New client func
|
|
|
|
func NewClient(name string, b func(...client.Option) client.Client) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Clients[name] = b
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// New registry func
|
2016-03-16 01:20:21 +03:00
|
|
|
func NewRegistry(name string, r func(...registry.Option) registry.Registry) Option {
|
2016-01-01 04:16:21 +03:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Registries[name] = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// New selector func
|
|
|
|
func NewSelector(name string, s func(...selector.Option) selector.Selector) Option {
|
2016-01-01 04:16:21 +03:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Selectors[name] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 20:29:26 +03:00
|
|
|
// New server func
|
|
|
|
func NewServer(name string, s func(...server.Option) server.Server) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Servers[name] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 03:38:57 +03:00
|
|
|
// New transport func
|
2016-03-16 01:25:32 +03:00
|
|
|
func NewTransport(name string, t func(...transport.Option) transport.Transport) Option {
|
2016-01-01 04:16:21 +03:00
|
|
|
return func(o *Options) {
|
|
|
|
o.Transports[name] = t
|
|
|
|
}
|
|
|
|
}
|
2019-11-02 16:25:10 +03:00
|
|
|
|
2020-06-24 13:46:51 +03:00
|
|
|
// New router func
|
|
|
|
func NewRouter(name string, r func(...router.Option) router.Router) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Routers[name] = r
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-02 16:25:10 +03:00
|
|
|
// New runtime func
|
|
|
|
func NewRuntime(name string, r func(...runtime.Option) runtime.Runtime) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Runtimes[name] = r
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 18:45:11 +03:00
|
|
|
|
|
|
|
// New tracer func
|
|
|
|
func NewTracer(name string, t func(...trace.Option) trace.Tracer) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Tracers[name] = t
|
|
|
|
}
|
|
|
|
}
|
2020-02-03 11:16:02 +03:00
|
|
|
|
|
|
|
// New auth func
|
|
|
|
func NewAuth(name string, t func(...auth.Option) auth.Auth) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Auths[name] = t
|
|
|
|
}
|
|
|
|
}
|