Add command option
This commit is contained in:
parent
eefb9c53d4
commit
2753520ee4
15
cmd/cmd.go
15
cmd/cmd.go
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/micro/go-micro/broker"
|
"github.com/micro/go-micro/broker"
|
||||||
"github.com/micro/go-micro/client"
|
"github.com/micro/go-micro/client"
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
|
"github.com/micro/go-micro/selector"
|
||||||
"github.com/micro/go-micro/server"
|
"github.com/micro/go-micro/server"
|
||||||
"github.com/micro/go-micro/transport"
|
"github.com/micro/go-micro/transport"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
@ -80,6 +81,12 @@ var (
|
|||||||
EnvVar: "MICRO_REGISTRY_ADDRESS",
|
EnvVar: "MICRO_REGISTRY_ADDRESS",
|
||||||
Usage: "Comma-separated list of registry addresses",
|
Usage: "Comma-separated list of registry addresses",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "selector",
|
||||||
|
EnvVar: "MICRO_SELECTOR",
|
||||||
|
Value: "selector",
|
||||||
|
Usage: "Selector used to pick nodes for querying. random, roundrobin, blacklist",
|
||||||
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "transport",
|
Name: "transport",
|
||||||
EnvVar: "MICRO_TRANSPORT",
|
EnvVar: "MICRO_TRANSPORT",
|
||||||
@ -137,6 +144,10 @@ var (
|
|||||||
"consul": registry.NewRegistry,
|
"consul": registry.NewRegistry,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Selectors = map[string]func(...selector.Option) selector.Selector{
|
||||||
|
"random": selector.NewSelector,
|
||||||
|
}
|
||||||
|
|
||||||
Transports = map[string]func([]string, ...transport.Option) transport.Transport{
|
Transports = map[string]func([]string, ...transport.Option) transport.Transport{
|
||||||
"http": transport.NewTransport,
|
"http": transport.NewTransport,
|
||||||
}
|
}
|
||||||
@ -214,6 +225,10 @@ func Setup(c *cli.Context) error {
|
|||||||
registry.DefaultRegistry = r(strings.Split(c.String("registry_address"), ","))
|
registry.DefaultRegistry = r(strings.Split(c.String("registry_address"), ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s, ok := Selectors[c.String("selector")]; ok {
|
||||||
|
selector.DefaultSelector = s(selector.Registry(registry.DefaultRegistry))
|
||||||
|
}
|
||||||
|
|
||||||
if t, ok := Transports[c.String("transport")]; ok {
|
if t, ok := Transports[c.String("transport")]; ok {
|
||||||
transport.DefaultTransport = t(strings.Split(c.String("transport_address"), ","))
|
transport.DefaultTransport = t(strings.Split(c.String("transport_address"), ","))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user