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

@@ -7,12 +7,13 @@ import (
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
"github.com/unistack-org/micro/v3/tracer"
)
// Options struct
type Options struct {
Name string
// Addrs useed by broker
Addrs []string
// ErrorHandler executed when errors occur processing messages
@@ -27,8 +28,8 @@ type Options struct {
Tracer tracer.Tracer
// TLSConfig for secure communication
TLSConfig *tls.Config
// Registry used for clustering
Registry registry.Registry
// Register used for clustering
Register register.Register
// Context is used for non default options
Context context.Context
}
@@ -36,7 +37,7 @@ type Options struct {
// NewOptions create new Options
func NewOptions(opts ...Option) Options {
options := Options{
Registry: registry.DefaultRegistry,
Register: register.DefaultRegister,
Logger: logger.DefaultLogger,
Context: context.Background(),
Meter: meter.DefaultMeter,
@@ -202,10 +203,10 @@ func SubscribeGroup(name string) SubscribeOption {
}
}
// Registry sets registry option
func Registry(r registry.Registry) Option {
// Register sets register option
func Register(r register.Register) Option {
return func(o *Options) {
o.Registry = r
o.Register = r
}
}
@@ -237,6 +238,13 @@ func Meter(m meter.Meter) Option {
}
}
// Name sets the name
func Name(n string) Option {
return func(o *Options) {
o.Name = n
}
}
// SubscribeContext set context
func SubscribeContext(ctx context.Context) SubscribeOption {
return func(o *SubscribeOptions) {