add router selector and network defaults
This commit is contained in:
@@ -7,10 +7,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
rselect "github.com/micro/go-micro/client/selector/router"
|
||||
"github.com/micro/go-micro/codec"
|
||||
"github.com/micro/go-micro/codec/bytes"
|
||||
"github.com/micro/go-micro/config/options"
|
||||
"github.com/micro/go-micro/network/proxy"
|
||||
"github.com/micro/go-micro/network/router"
|
||||
"github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
@@ -162,5 +164,18 @@ func NewProxy(opts ...options.Option) proxy.Proxy {
|
||||
p.Client = c.(client.Client)
|
||||
}
|
||||
|
||||
// get router
|
||||
r, ok := p.Options.Values().Get("proxy.router")
|
||||
if ok {
|
||||
// set the router in the client
|
||||
p.Client.Init(
|
||||
// pass new selector as an option to the client
|
||||
client.Selector(rselect.NewSelector(
|
||||
// set the router in the selector
|
||||
rselect.WithRouter(r.(router.Router)),
|
||||
)),
|
||||
)
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/micro/go-micro/client"
|
||||
"github.com/micro/go-micro/config/options"
|
||||
"github.com/micro/go-micro/network/router"
|
||||
"github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
@@ -29,3 +30,8 @@ func WithEndpoint(e string) options.Option {
|
||||
func WithClient(c client.Client) options.Option {
|
||||
return options.WithValue("proxy.client", c)
|
||||
}
|
||||
|
||||
// WithRouter specifies the router to use
|
||||
func WithRouter(r router.Router) options.Option {
|
||||
return options.WithValue("proxy.router", r)
|
||||
}
|
||||
|
Reference in New Issue
Block a user