micro: rewrite options to support multiple building blocks

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-01-29 13:17:32 +03:00
parent ac8a3a12c4
commit 827d467077
57 changed files with 1283 additions and 644 deletions

View File

@@ -9,7 +9,7 @@ import (
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/network/transport"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
"github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/selector"
"github.com/unistack-org/micro/v3/selector/random"
@@ -18,6 +18,7 @@ import (
// Options holds client options
type Options struct {
Name string
// Used to select codec
ContentType string
// Proxy address to send requests via
@@ -246,11 +247,11 @@ func Transport(t transport.Transport) Option {
}
}
// Registry sets the routers registry
func Registry(r registry.Registry) Option {
// Register sets the routers register
func Register(r register.Register) Option {
return func(o *Options) {
if o.Router != nil {
o.Router.Init(router.Registry(r))
o.Router.Init(router.Register(r))
}
}
}
@@ -291,6 +292,13 @@ func Backoff(fn BackoffFunc) Option {
}
}
// Name sets the client name
func Name(n string) Option {
return func(o *Options) {
o.Name = n
}
}
// Lookup sets the lookup function to use for resolving service names
func Lookup(l LookupFunc) Option {
return func(o *Options) {