mirror of
https://github.com/go-micro/go-micro.git
synced 2025-05-25 21:53:14 +02:00
fix: set DefaultX for cli flag and service option
This commit is contained in:
parent
45fe92d748
commit
cb46674ae6
11
cmd/cmd.go
11
cmd/cmd.go
@ -367,6 +367,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
// only change if we have the client and type differs
|
||||
if cl, ok := c.opts.Clients[name]; ok && (*c.opts.Client).String() != name {
|
||||
*c.opts.Client = cl()
|
||||
client.DefaultClient = *c.opts.Client
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,6 +376,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
// only change if we have the server and type differs
|
||||
if s, ok := c.opts.Servers[name]; ok && (*c.opts.Server).String() != name {
|
||||
*c.opts.Server = s()
|
||||
server.DefaultServer = *c.opts.Server
|
||||
}
|
||||
}
|
||||
|
||||
@ -386,6 +388,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
*c.opts.Store = s(store.WithClient(*c.opts.Client))
|
||||
store.DefaultStore = *c.opts.Store
|
||||
}
|
||||
|
||||
// Set the tracer
|
||||
@ -396,6 +399,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
*c.opts.Tracer = r()
|
||||
trace.DefaultTracer = *c.opts.Tracer
|
||||
}
|
||||
|
||||
// Setup auth
|
||||
@ -422,6 +426,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
*c.opts.Auth = r(authOpts...)
|
||||
auth.DefaultAuth = *c.opts.Auth
|
||||
}
|
||||
|
||||
// Set the registry
|
||||
@ -444,6 +449,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
if err := (*c.opts.Broker).Init(broker.Registry(*c.opts.Registry)); err != nil {
|
||||
logger.Fatalf("Error configuring broker: %v", err)
|
||||
}
|
||||
registry.DefaultRegistry = *c.opts.Registry
|
||||
}
|
||||
|
||||
// Set the profile
|
||||
@ -454,6 +460,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
*c.opts.Profile = p()
|
||||
profile.DefaultProfile = *c.opts.Profile
|
||||
}
|
||||
|
||||
// Set the broker
|
||||
@ -466,6 +473,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
*c.opts.Broker = b()
|
||||
serverOpts = append(serverOpts, server.Broker(*c.opts.Broker))
|
||||
clientOpts = append(clientOpts, client.Broker(*c.opts.Broker))
|
||||
broker.DefaultBroker = *c.opts.Broker
|
||||
}
|
||||
|
||||
// Set the selector
|
||||
@ -479,6 +487,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
|
||||
// No server option here. Should there be?
|
||||
clientOpts = append(clientOpts, client.Selector(*c.opts.Selector))
|
||||
selector.DefaultSelector = *c.opts.Selector
|
||||
}
|
||||
|
||||
// Set the transport
|
||||
@ -491,6 +500,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
*c.opts.Transport = t()
|
||||
serverOpts = append(serverOpts, server.Transport(*c.opts.Transport))
|
||||
clientOpts = append(clientOpts, client.Transport(*c.opts.Transport))
|
||||
transport.DefaultTransport = *c.opts.Transport
|
||||
}
|
||||
|
||||
// Parse the server options
|
||||
@ -630,6 +640,7 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
||||
logger.Fatalf("Error configuring config: %v", err)
|
||||
}
|
||||
*c.opts.Config = rc
|
||||
config.DefaultConfig = *c.opts.Config
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,72 +81,84 @@ func Version(v string) Option {
|
||||
func Broker(b *broker.Broker) Option {
|
||||
return func(o *Options) {
|
||||
o.Broker = b
|
||||
broker.DefaultBroker = *b
|
||||
}
|
||||
}
|
||||
|
||||
func Cache(c *cache.Cache) Option {
|
||||
return func(o *Options) {
|
||||
o.Cache = c
|
||||
cache.DefaultCache = *c
|
||||
}
|
||||
}
|
||||
|
||||
func Config(c *config.Config) Option {
|
||||
return func(o *Options) {
|
||||
o.Config = c
|
||||
config.DefaultConfig = *c
|
||||
}
|
||||
}
|
||||
|
||||
func Selector(s *selector.Selector) Option {
|
||||
return func(o *Options) {
|
||||
o.Selector = s
|
||||
selector.DefaultSelector = *s
|
||||
}
|
||||
}
|
||||
|
||||
func Registry(r *registry.Registry) Option {
|
||||
return func(o *Options) {
|
||||
o.Registry = r
|
||||
registry.DefaultRegistry = *r
|
||||
}
|
||||
}
|
||||
|
||||
func Transport(t *transport.Transport) Option {
|
||||
return func(o *Options) {
|
||||
o.Transport = t
|
||||
transport.DefaultTransport = *t
|
||||
}
|
||||
}
|
||||
|
||||
func Client(c *client.Client) Option {
|
||||
return func(o *Options) {
|
||||
o.Client = c
|
||||
client.DefaultClient = *c
|
||||
}
|
||||
}
|
||||
|
||||
func Server(s *server.Server) Option {
|
||||
return func(o *Options) {
|
||||
o.Server = s
|
||||
server.DefaultServer = *s
|
||||
}
|
||||
}
|
||||
|
||||
func Store(s *store.Store) Option {
|
||||
return func(o *Options) {
|
||||
o.Store = s
|
||||
store.DefaultStore = *s
|
||||
}
|
||||
}
|
||||
|
||||
func Tracer(t *trace.Tracer) Option {
|
||||
return func(o *Options) {
|
||||
o.Tracer = t
|
||||
trace.DefaultTracer = *t
|
||||
}
|
||||
}
|
||||
|
||||
func Auth(a *auth.Auth) Option {
|
||||
return func(o *Options) {
|
||||
o.Auth = a
|
||||
auth.DefaultAuth = *a
|
||||
}
|
||||
}
|
||||
|
||||
func Profile(p *profile.Profile) Option {
|
||||
return func(o *Options) {
|
||||
o.Profile = p
|
||||
profile.DefaultProfile = *p
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,12 +83,14 @@ func Broker(b broker.Broker) Option {
|
||||
// Update Client and Server
|
||||
o.Client.Init(client.Broker(b))
|
||||
o.Server.Init(server.Broker(b))
|
||||
broker.DefaultBroker = b
|
||||
}
|
||||
}
|
||||
|
||||
func Cache(c cache.Cache) Option {
|
||||
return func(o *Options) {
|
||||
o.Cache = c
|
||||
cache.DefaultCache = c
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,6 +104,7 @@ func Cmd(c cmd.Cmd) Option {
|
||||
func Client(c client.Client) Option {
|
||||
return func(o *Options) {
|
||||
o.Client = c
|
||||
client.DefaultClient = c
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,6 +138,7 @@ func HandleSignal(b bool) Option {
|
||||
func Profile(p profile.Profile) Option {
|
||||
return func(o *Options) {
|
||||
o.Profile = p
|
||||
profile.DefaultProfile = p
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,6 +146,7 @@ func Profile(p profile.Profile) Option {
|
||||
func Server(s server.Server) Option {
|
||||
return func(o *Options) {
|
||||
o.Server = s
|
||||
server.DefaultServer = s
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,6 +154,7 @@ func Server(s server.Server) Option {
|
||||
func Store(s store.Store) Option {
|
||||
return func(o *Options) {
|
||||
o.Store = s
|
||||
store.DefaultStore = s
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,6 +168,7 @@ func Registry(r registry.Registry) Option {
|
||||
o.Server.Init(server.Registry(r))
|
||||
// Update Broker
|
||||
o.Broker.Init(broker.Registry(r))
|
||||
broker.DefaultBroker = o.Broker
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,12 +177,15 @@ func Tracer(t trace.Tracer) Option {
|
||||
return func(o *Options) {
|
||||
o.Server.Init(server.Tracer(t))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Auth sets the auth for the service.
|
||||
func Auth(a auth.Auth) Option {
|
||||
return func(o *Options) {
|
||||
o.Auth = a
|
||||
auth.DefaultAuth = a
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,6 +193,7 @@ func Auth(a auth.Auth) Option {
|
||||
func Config(c config.Config) Option {
|
||||
return func(o *Options) {
|
||||
o.Config = c
|
||||
config.DefaultConfig = c
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,6 +201,7 @@ func Config(c config.Config) Option {
|
||||
func Selector(s selector.Selector) Option {
|
||||
return func(o *Options) {
|
||||
o.Client.Init(client.Selector(s))
|
||||
selector.DefaultSelector = s
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,6 +213,7 @@ func Transport(t transport.Transport) Option {
|
||||
// Update Client and Server
|
||||
o.Client.Init(client.Transport(t))
|
||||
o.Server.Init(server.Transport(t))
|
||||
transport.DefaultTransport = t
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user