Don't add to defaults in func init, just add them to cmd
This commit is contained in:
parent
f7c57fd4f4
commit
3d3044404e
@ -2,13 +2,8 @@ package http
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/micro/go-micro/broker"
|
"github.com/micro/go-micro/broker"
|
||||||
"github.com/micro/go-micro/cmd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.DefaultBrokers["http"] = NewBroker
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBroker(opts ...broker.Option) broker.Broker {
|
func NewBroker(opts ...broker.Option) broker.Broker {
|
||||||
return broker.NewBroker(opts...)
|
return broker.NewBroker(opts...)
|
||||||
}
|
}
|
||||||
|
34
cmd/cmd.go
34
cmd/cmd.go
@ -9,13 +9,28 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/micro/cli"
|
"github.com/micro/cli"
|
||||||
"github.com/micro/go-micro/broker"
|
|
||||||
"github.com/micro/go-micro/broker/mqtt"
|
|
||||||
"github.com/micro/go-micro/client"
|
"github.com/micro/go-micro/client"
|
||||||
"github.com/micro/go-micro/registry"
|
|
||||||
"github.com/micro/go-micro/selector"
|
|
||||||
"github.com/micro/go-micro/server"
|
"github.com/micro/go-micro/server"
|
||||||
|
|
||||||
|
// brokers
|
||||||
|
"github.com/micro/go-micro/broker"
|
||||||
|
"github.com/micro/go-micro/broker/http"
|
||||||
|
"github.com/micro/go-micro/broker/mqtt"
|
||||||
|
|
||||||
|
// registries
|
||||||
|
"github.com/micro/go-micro/registry"
|
||||||
|
"github.com/micro/go-micro/registry/consul"
|
||||||
|
|
||||||
|
// selectors
|
||||||
|
"github.com/micro/go-micro/selector"
|
||||||
|
"github.com/micro/go-micro/selector/blacklist"
|
||||||
|
"github.com/micro/go-micro/selector/cache"
|
||||||
|
"github.com/micro/go-micro/selector/random"
|
||||||
|
"github.com/micro/go-micro/selector/roundrobin"
|
||||||
|
|
||||||
|
// transports
|
||||||
"github.com/micro/go-micro/transport"
|
"github.com/micro/go-micro/transport"
|
||||||
|
thttp "github.com/micro/go-micro/transport/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Cmd interface {
|
type Cmd interface {
|
||||||
@ -118,20 +133,23 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
DefaultBrokers = map[string]func(...broker.Option) broker.Broker{
|
DefaultBrokers = map[string]func(...broker.Option) broker.Broker{
|
||||||
"http": broker.NewBroker,
|
"http": http.NewBroker,
|
||||||
"mqtt": mqtt.NewBroker,
|
"mqtt": mqtt.NewBroker,
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
|
DefaultRegistries = map[string]func(...registry.Option) registry.Registry{
|
||||||
"consul": registry.NewRegistry,
|
"consul": consul.NewRegistry,
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultSelectors = map[string]func(...selector.Option) selector.Selector{
|
DefaultSelectors = map[string]func(...selector.Option) selector.Selector{
|
||||||
"random": selector.NewSelector,
|
"cache": cache.NewSelector,
|
||||||
|
"random": random.NewSelector,
|
||||||
|
"roundrobin": roundrobin.NewSelector,
|
||||||
|
"blacklist": blacklist.NewSelector,
|
||||||
}
|
}
|
||||||
|
|
||||||
DefaultTransports = map[string]func(...transport.Option) transport.Transport{
|
DefaultTransports = map[string]func(...transport.Option) transport.Transport{
|
||||||
"http": transport.NewTransport,
|
"http": thttp.NewTransport,
|
||||||
}
|
}
|
||||||
|
|
||||||
// used for default selection as the fall back
|
// used for default selection as the fall back
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
package consul
|
package consul
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/micro/go-micro/cmd"
|
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.DefaultRegistries["consul"] = NewRegistry
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRegistry(opts ...registry.Option) registry.Registry {
|
func NewRegistry(opts ...registry.Option) registry.Registry {
|
||||||
return registry.NewRegistry(opts...)
|
return registry.NewRegistry(opts...)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/micro/go-micro/cmd"
|
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
"github.com/micro/go-micro/selector"
|
"github.com/micro/go-micro/selector"
|
||||||
)
|
)
|
||||||
@ -27,7 +26,6 @@ type blackListSelector struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd.DefaultSelectors["blacklist"] = NewSelector
|
|
||||||
rand.Seed(time.Now().Unix())
|
rand.Seed(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
package random
|
package random
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/micro/go-micro/cmd"
|
|
||||||
"github.com/micro/go-micro/selector"
|
"github.com/micro/go-micro/selector"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.DefaultSelectors["random"] = NewSelector
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSelector(opts ...selector.Option) selector.Selector {
|
func NewSelector(opts ...selector.Option) selector.Selector {
|
||||||
return selector.NewSelector(opts...)
|
return selector.NewSelector(opts...)
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package roundrobin
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/micro/go-micro/cmd"
|
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
"github.com/micro/go-micro/selector"
|
"github.com/micro/go-micro/selector"
|
||||||
)
|
)
|
||||||
@ -12,10 +11,6 @@ type roundRobinSelector struct {
|
|||||||
so selector.Options
|
so selector.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.DefaultSelectors["roundrobin"] = NewSelector
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *roundRobinSelector) Init(opts ...selector.Option) error {
|
func (r *roundRobinSelector) Init(opts ...selector.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&r.so)
|
o(&r.so)
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/micro/go-micro/cmd"
|
|
||||||
"github.com/micro/go-micro/transport"
|
"github.com/micro/go-micro/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cmd.DefaultTransports["http"] = NewTransport
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTransport(opts ...transport.Option) transport.Transport {
|
func NewTransport(opts ...transport.Option) transport.Transport {
|
||||||
return transport.NewTransport(opts...)
|
return transport.NewTransport(opts...)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user