add logger to options
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
2382446e10
commit
53654185ba
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/store"
|
"github.com/unistack-org/micro/v3/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ type Options struct {
|
|||||||
Store store.Store
|
Store store.Store
|
||||||
// Addrs sets the addresses of auth
|
// Addrs sets the addresses of auth
|
||||||
Addrs []string
|
Addrs []string
|
||||||
|
// Logger sets the logger
|
||||||
|
Logger logger.Logger
|
||||||
// Context to store other options
|
// Context to store other options
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"github.com/unistack-org/micro/v3/codec"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
"github.com/unistack-org/micro/v3/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,6 +14,8 @@ type Options struct {
|
|||||||
Secure bool
|
Secure bool
|
||||||
Codec codec.Marshaler
|
Codec codec.Marshaler
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
// Handler executed when errors occur processing messages
|
// Handler executed when errors occur processing messages
|
||||||
ErrorHandler Handler
|
ErrorHandler Handler
|
||||||
|
|
||||||
@ -145,6 +148,13 @@ func TLSConfig(t *tls.Config) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SubscribeContext set context
|
// SubscribeContext set context
|
||||||
func SubscribeContext(ctx context.Context) SubscribeOption {
|
func SubscribeContext(ctx context.Context) SubscribeOption {
|
||||||
return func(o *SubscribeOptions) {
|
return func(o *SubscribeOptions) {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/unistack-org/micro/v3/broker"
|
"github.com/unistack-org/micro/v3/broker"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"github.com/unistack-org/micro/v3/codec"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
"github.com/unistack-org/micro/v3/registry"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"github.com/unistack-org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/selector"
|
"github.com/unistack-org/micro/v3/selector"
|
||||||
@ -25,7 +26,7 @@ type Options struct {
|
|||||||
Router router.Router
|
Router router.Router
|
||||||
Selector selector.Selector
|
Selector selector.Selector
|
||||||
Transport transport.Transport
|
Transport transport.Transport
|
||||||
|
Logger logger.Logger
|
||||||
// Lookup used for looking up routes
|
// Lookup used for looking up routes
|
||||||
Lookup LookupFunc
|
Lookup LookupFunc
|
||||||
|
|
||||||
@ -137,6 +138,12 @@ func Broker(b broker.Broker) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Codec to be used to encode/decode requests for a given content type
|
// Codec to be used to encode/decode requests for a given content type
|
||||||
func Codec(contentType string, c codec.NewCodec) Option {
|
func Codec(contentType string, c codec.NewCodec) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
@ -182,7 +189,9 @@ func Transport(t transport.Transport) Option {
|
|||||||
// Registry sets the routers registry
|
// Registry sets the routers registry
|
||||||
func Registry(r registry.Registry) Option {
|
func Registry(r registry.Registry) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Router.Init(router.Registry(r))
|
if o.Router != nil {
|
||||||
|
o.Router.Init(router.Registry(r))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
|
import "github.com/unistack-org/micro/v3/logger"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// The Prometheus metrics will be made available on this port:
|
// The Prometheus metrics will be made available on this port:
|
||||||
defaultPrometheusListenAddress = ":9000"
|
defaultPrometheusListenAddress = ":9000"
|
||||||
@ -18,6 +20,7 @@ type Options struct {
|
|||||||
Path string
|
Path string
|
||||||
DefaultTags Tags
|
DefaultTags Tags
|
||||||
TimingObjectives map[float64]float64
|
TimingObjectives map[float64]float64
|
||||||
|
Logger logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOptions prepares a set of options:
|
// NewOptions prepares a set of options:
|
||||||
@ -63,3 +66,10 @@ func TimingObjectives(value map[float64]float64) Option {
|
|||||||
o.TimingObjectives = value
|
o.TimingObjectives = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ package network
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/proxy"
|
"github.com/unistack-org/micro/v3/proxy"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"github.com/unistack-org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/tunnel"
|
"github.com/unistack-org/micro/v3/tunnel"
|
||||||
@ -27,6 +28,8 @@ type Options struct {
|
|||||||
Router router.Router
|
Router router.Router
|
||||||
// Proxy is network proxy
|
// Proxy is network proxy
|
||||||
Proxy proxy.Proxy
|
Proxy proxy.Proxy
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id sets the id of the network node
|
// Id sets the id of the network node
|
||||||
@ -85,6 +88,13 @@ func Proxy(p proxy.Proxy) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the network logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultOptions returns network default options
|
// DefaultOptions returns network default options
|
||||||
func DefaultOptions() Options {
|
func DefaultOptions() Options {
|
||||||
return Options{
|
return Options{
|
||||||
|
110
options.go
110
options.go
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/unistack-org/micro/v3/config"
|
"github.com/unistack-org/micro/v3/config"
|
||||||
"github.com/unistack-org/micro/v3/debug/profile"
|
"github.com/unistack-org/micro/v3/debug/profile"
|
||||||
"github.com/unistack-org/micro/v3/debug/trace"
|
"github.com/unistack-org/micro/v3/debug/trace"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
"github.com/unistack-org/micro/v3/registry"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"github.com/unistack-org/micro/v3/router"
|
||||||
"github.com/unistack-org/micro/v3/runtime"
|
"github.com/unistack-org/micro/v3/runtime"
|
||||||
@ -25,6 +26,7 @@ import (
|
|||||||
type Options struct {
|
type Options struct {
|
||||||
Auth auth.Auth
|
Auth auth.Auth
|
||||||
Broker broker.Broker
|
Broker broker.Broker
|
||||||
|
Logger logger.Logger
|
||||||
Cmd cmd.Cmd
|
Cmd cmd.Cmd
|
||||||
Config config.Config
|
Config config.Config
|
||||||
Client client.Client
|
Client client.Client
|
||||||
@ -51,8 +53,20 @@ type Options struct {
|
|||||||
|
|
||||||
func newOptions(opts ...Option) Options {
|
func newOptions(opts ...Option) Options {
|
||||||
opt := Options{
|
opt := Options{
|
||||||
Context: context.Background(),
|
Context: context.Background(),
|
||||||
Signal: true,
|
Signal: true,
|
||||||
|
Server: server.DefaultServer,
|
||||||
|
Client: client.DefaultClient,
|
||||||
|
Broker: broker.DefaultBroker,
|
||||||
|
Registry: registry.DefaultRegistry,
|
||||||
|
Router: router.DefaultRouter,
|
||||||
|
Auth: auth.DefaultAuth,
|
||||||
|
Logger: logger.DefaultLogger,
|
||||||
|
Config: config.DefaultConfig,
|
||||||
|
Store: store.DefaultStore,
|
||||||
|
Transport: transport.DefaultTransport,
|
||||||
|
//Runtime runtime.Runtime
|
||||||
|
//Profile profile.Profile
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
@ -68,9 +82,13 @@ type Option func(*Options)
|
|||||||
func Broker(b broker.Broker) Option {
|
func Broker(b broker.Broker) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Broker = b
|
o.Broker = b
|
||||||
// Update Client and Server
|
if o.Client != nil {
|
||||||
o.Client.Init(client.Broker(b))
|
// Update Client and Server
|
||||||
o.Server.Init(server.Broker(b))
|
o.Client.Init(client.Broker(b))
|
||||||
|
}
|
||||||
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Broker(b))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,24 +143,40 @@ func Store(s store.Store) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger set the logger to use
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Registry sets the registry for the service
|
// Registry sets the registry for the service
|
||||||
// and the underlying components
|
// and the underlying components
|
||||||
func Registry(r registry.Registry) Option {
|
func Registry(r registry.Registry) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Registry = r
|
o.Registry = r
|
||||||
// Update router
|
if o.Router != nil {
|
||||||
o.Router.Init(router.Registry(r))
|
// Update router
|
||||||
// Update server
|
o.Router.Init(router.Registry(r))
|
||||||
o.Server.Init(server.Registry(r))
|
}
|
||||||
// Update Broker
|
if o.Server != nil {
|
||||||
o.Broker.Init(broker.Registry(r))
|
// Update server
|
||||||
|
o.Server.Init(server.Registry(r))
|
||||||
|
}
|
||||||
|
if o.Broker != nil {
|
||||||
|
// Update Broker
|
||||||
|
o.Broker.Init(broker.Registry(r))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tracer sets the tracer for the service
|
// Tracer sets the tracer for the service
|
||||||
func Tracer(t trace.Tracer) Option {
|
func Tracer(t trace.Tracer) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.Tracer(t))
|
if o.Server != nil {
|
||||||
|
//todo client trace
|
||||||
|
o.Server.Init(server.Tracer(t))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +184,9 @@ func Tracer(t trace.Tracer) Option {
|
|||||||
func Auth(a auth.Auth) Option {
|
func Auth(a auth.Auth) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Auth = a
|
o.Auth = a
|
||||||
o.Server.Init(server.Auth(a))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Auth(a))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +200,9 @@ func Config(c config.Config) Option {
|
|||||||
// Selector sets the selector for the service client
|
// Selector sets the selector for the service client
|
||||||
func Selector(s selector.Selector) Option {
|
func Selector(s selector.Selector) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Client.Init(client.Selector(s))
|
if o.Client != nil {
|
||||||
|
o.Client.Init(client.Selector(s))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +212,12 @@ func Transport(t transport.Transport) Option {
|
|||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Transport = t
|
o.Transport = t
|
||||||
// Update Client and Server
|
// Update Client and Server
|
||||||
o.Client.Init(client.Transport(t))
|
if o.Client != nil {
|
||||||
o.Server.Init(server.Transport(t))
|
o.Client.Init(client.Transport(t))
|
||||||
|
}
|
||||||
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Transport(t))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +233,9 @@ func Router(r router.Router) Option {
|
|||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Router = r
|
o.Router = r
|
||||||
// Update client
|
// Update client
|
||||||
o.Client.Init(client.Router(r))
|
if o.Client != nil {
|
||||||
|
o.Client.Init(client.Router(r))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,56 +244,72 @@ func Router(r router.Router) Option {
|
|||||||
// Address sets the address of the server
|
// Address sets the address of the server
|
||||||
func Address(addr string) Option {
|
func Address(addr string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.Address(addr))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Address(addr))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name of the service
|
// Name of the service
|
||||||
func Name(n string) Option {
|
func Name(n string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.Name(n))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Name(n))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Version of the service
|
// Version of the service
|
||||||
func Version(v string) Option {
|
func Version(v string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.Version(v))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Version(v))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Metadata associated with the service
|
// Metadata associated with the service
|
||||||
func Metadata(md map[string]string) Option {
|
func Metadata(md map[string]string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.Metadata(md))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.Metadata(md))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flags that can be passed to service
|
// Flags that can be passed to service
|
||||||
func Flags(flags ...cli.Flag) Option {
|
func Flags(flags ...cli.Flag) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Cmd.App().Flags = append(o.Cmd.App().Flags, flags...)
|
if o.Cmd != nil {
|
||||||
|
o.Cmd.App().Flags = append(o.Cmd.App().Flags, flags...)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Action can be used to parse user provided cli options
|
// Action can be used to parse user provided cli options
|
||||||
func Action(a func(*cli.Context) error) Option {
|
func Action(a func(*cli.Context) error) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Cmd.App().Action = a
|
if o.Cmd != nil {
|
||||||
|
o.Cmd.App().Action = a
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterTTL specifies the TTL to use when registering the service
|
// RegisterTTL specifies the TTL to use when registering the service
|
||||||
func RegisterTTL(t time.Duration) Option {
|
func RegisterTTL(t time.Duration) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.RegisterTTL(t))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.RegisterTTL(t))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterInterval specifies the interval on which to re-register
|
// RegisterInterval specifies the interval on which to re-register
|
||||||
func RegisterInterval(t time.Duration) Option {
|
func RegisterInterval(t time.Duration) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
o.Server.Init(server.RegisterInterval(t))
|
if o.Server != nil {
|
||||||
|
o.Server.Init(server.RegisterInterval(t))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package proxy
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"github.com/unistack-org/micro/v3/client"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/router"
|
"github.com/unistack-org/micro/v3/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,6 +17,8 @@ type Options struct {
|
|||||||
Router router.Router
|
Router router.Router
|
||||||
// Extra links for different clients
|
// Extra links for different clients
|
||||||
Links map[string]client.Client
|
Links map[string]client.Client
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option func signature
|
// Option func signature
|
||||||
@ -42,6 +45,13 @@ func WithRouter(r router.Router) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithLogger specifies the logger to use
|
||||||
|
func WithLogger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WithLink sets a link for outbound requests
|
// WithLink sets a link for outbound requests
|
||||||
func WithLink(name string, c client.Client) Option {
|
func WithLink(name string, c client.Client) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
@ -11,6 +13,7 @@ type Options struct {
|
|||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
Secure bool
|
Secure bool
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
Logger logger.Logger
|
||||||
// Other options for implementations of the interface
|
// Other options for implementations of the interface
|
||||||
// can be stored in a context
|
// can be stored in a context
|
||||||
Context context.Context
|
Context context.Context
|
||||||
@ -74,6 +77,13 @@ func Secure(b bool) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Specify TLS Config
|
// Specify TLS Config
|
||||||
func TLSConfig(t *tls.Config) Option {
|
func TLSConfig(t *tls.Config) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
"github.com/unistack-org/micro/v3/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,10 +20,12 @@ type Options struct {
|
|||||||
Network string
|
Network string
|
||||||
// Registry is the local registry
|
// Registry is the local registry
|
||||||
Registry registry.Registry
|
Registry registry.Registry
|
||||||
// Context for additional options
|
|
||||||
Context context.Context
|
|
||||||
// Precache routes
|
// Precache routes
|
||||||
Precache bool
|
Precache bool
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
|
// Context for additional options
|
||||||
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id sets Router Id
|
// Id sets Router Id
|
||||||
@ -53,6 +56,13 @@ func Network(n string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Registry sets the local registry
|
// Registry sets the local registry
|
||||||
func Registry(r registry.Registry) Option {
|
func Registry(r registry.Registry) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"github.com/unistack-org/micro/v3/client"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Option func(o *Options)
|
type Option func(o *Options)
|
||||||
@ -21,6 +22,15 @@ type Options struct {
|
|||||||
Image string
|
Image string
|
||||||
// Client to use when making requests
|
// Client to use when making requests
|
||||||
Client client.Client
|
Client client.Client
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithLogger sets the logger
|
||||||
|
func WithLogger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSource sets the base image / repository
|
// WithSource sets the base image / repository
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/unistack-org/micro/v3/broker"
|
"github.com/unistack-org/micro/v3/broker"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"github.com/unistack-org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/debug/trace"
|
"github.com/unistack-org/micro/v3/debug/trace"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/registry"
|
"github.com/unistack-org/micro/v3/registry"
|
||||||
"github.com/unistack-org/micro/v3/transport"
|
"github.com/unistack-org/micro/v3/transport"
|
||||||
)
|
)
|
||||||
@ -20,6 +21,7 @@ type Options struct {
|
|||||||
Registry registry.Registry
|
Registry registry.Registry
|
||||||
Tracer trace.Tracer
|
Tracer trace.Tracer
|
||||||
Auth auth.Auth
|
Auth auth.Auth
|
||||||
|
Logger logger.Logger
|
||||||
Transport transport.Transport
|
Transport transport.Transport
|
||||||
Metadata map[string]string
|
Metadata map[string]string
|
||||||
Name string
|
Name string
|
||||||
@ -98,6 +100,13 @@ func Namespace(n string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Unique server id
|
// Unique server id
|
||||||
func Id(id string) Option {
|
func Id(id string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
@ -3,6 +3,8 @@ package store
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Options contains configuration for the Store
|
// Options contains configuration for the Store
|
||||||
@ -15,6 +17,8 @@ type Options struct {
|
|||||||
Database string
|
Database string
|
||||||
// Table is analag for a table in database backends or a key prefix in KV backends
|
// Table is analag for a table in database backends or a key prefix in KV backends
|
||||||
Table string
|
Table string
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
// Context should contain all implementation specific options, using context.WithValue.
|
// Context should contain all implementation specific options, using context.WithValue.
|
||||||
Context context.Context
|
Context context.Context
|
||||||
}
|
}
|
||||||
@ -22,6 +26,13 @@ type Options struct {
|
|||||||
// Option sets values in Options
|
// Option sets values in Options
|
||||||
type Option func(o *Options)
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Nodes contains the addresses or other connection information of the backing storage.
|
// Nodes contains the addresses or other connection information of the backing storage.
|
||||||
// For example, an etcd implementation would contain the nodes of the cluster.
|
// For example, an etcd implementation would contain the nodes of the cluster.
|
||||||
// A SQL implementation could contain one or more connection strings.
|
// A SQL implementation could contain one or more connection strings.
|
||||||
|
@ -2,8 +2,36 @@ package sync
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
Nodes []string
|
||||||
|
Prefix string
|
||||||
|
Logger logger.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(o *Options)
|
||||||
|
|
||||||
|
type LeaderOptions struct{}
|
||||||
|
|
||||||
|
type LeaderOption func(o *LeaderOptions)
|
||||||
|
|
||||||
|
type LockOptions struct {
|
||||||
|
TTL time.Duration
|
||||||
|
Wait time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
type LockOption func(o *LockOptions)
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Nodes sets the addresses to use
|
// Nodes sets the addresses to use
|
||||||
func Nodes(a ...string) Option {
|
func Nodes(a ...string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
19
sync/sync.go
19
sync/sync.go
@ -3,7 +3,6 @@ package sync
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -33,21 +32,3 @@ type Leader interface {
|
|||||||
// status returns when leadership is lost
|
// status returns when leadership is lost
|
||||||
Status() chan bool
|
Status() chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Options struct {
|
|
||||||
Nodes []string
|
|
||||||
Prefix string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Option func(o *Options)
|
|
||||||
|
|
||||||
type LeaderOptions struct{}
|
|
||||||
|
|
||||||
type LeaderOption func(o *LeaderOptions)
|
|
||||||
|
|
||||||
type LockOptions struct {
|
|
||||||
TTL time.Duration
|
|
||||||
Wait time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
type LockOption func(o *LockOptions)
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"github.com/unistack-org/micro/v3/codec"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
@ -23,6 +24,8 @@ type Options struct {
|
|||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
// Timeout sets the timeout for Send/Recv
|
// Timeout sets the timeout for Send/Recv
|
||||||
Timeout time.Duration
|
Timeout time.Duration
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
// Other options for implementations of the interface
|
// Other options for implementations of the interface
|
||||||
// can be stored in a context
|
// can be stored in a context
|
||||||
Context context.Context
|
Context context.Context
|
||||||
@ -59,6 +62,13 @@ func Addrs(addrs ...string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Codec sets the codec used for encoding where the transport
|
// Codec sets the codec used for encoding where the transport
|
||||||
// does not support message headers
|
// does not support message headers
|
||||||
func Codec(c codec.Marshaler) Option {
|
func Codec(c codec.Marshaler) Option {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
"github.com/unistack-org/micro/v3/transport"
|
"github.com/unistack-org/micro/v3/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,6 +29,8 @@ type Options struct {
|
|||||||
Token string
|
Token string
|
||||||
// Transport listens to incoming connections
|
// Transport listens to incoming connections
|
||||||
Transport transport.Transport
|
Transport transport.Transport
|
||||||
|
// Logger
|
||||||
|
Logger logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
type DialOption func(*DialOptions)
|
type DialOption func(*DialOptions)
|
||||||
@ -59,6 +62,13 @@ func Id(id string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logger sets the logger
|
||||||
|
func Logger(l logger.Logger) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.Logger = l
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The tunnel address
|
// The tunnel address
|
||||||
func Address(a string) Option {
|
func Address(a string) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user