From a754ff7c0c3da2fb60bd49caa42e8ef8447cfa18 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 9 Dec 2020 12:10:25 +0300 Subject: [PATCH] more lint fixes Signed-off-by: Vasiliy Tolstov --- auth/options.go | 29 ++++++++++++++++++++++++++++- broker/options.go | 6 ++++-- config/options.go | 1 + network/transport/options.go | 2 +- registry/options.go | 4 +++- store/options.go | 2 +- tracer/options.go | 14 +++++++++++++- 7 files changed, 51 insertions(+), 7 deletions(-) diff --git a/auth/options.go b/auth/options.go index 225c5194..49157a48 100644 --- a/auth/options.go +++ b/auth/options.go @@ -9,8 +9,11 @@ import ( "github.com/unistack-org/micro/v3/store" ) +// NewOptions creates Options struct from slice of options func NewOptions(opts ...Option) Options { - var options Options + options := Options{ + Logger: logger.DefaultLogger, + } for _, o := range opts { o(&options) } @@ -42,6 +45,7 @@ type Options struct { Context context.Context } +// Option func type Option func(o *Options) // Addrs is the auth addresses to use @@ -101,6 +105,7 @@ func LoginURL(url string) Option { } } +// GenerateOptions struct type GenerateOptions struct { // Metadata associated with the account Metadata metadata.Metadata @@ -116,6 +121,7 @@ type GenerateOptions struct { Issuer string } +// GenerateOption func type GenerateOption func(o *GenerateOptions) // WithSecret for the generated account @@ -169,6 +175,7 @@ func NewGenerateOptions(opts ...GenerateOption) GenerateOptions { return options } +// TokenOptions struct type TokenOptions struct { // ID for the account ID string @@ -182,6 +189,7 @@ type TokenOptions struct { Issuer string } +// TokenOption func type TokenOption func(o *TokenOptions) // WithExpiry for the token @@ -191,6 +199,7 @@ func WithExpiry(ex time.Duration) TokenOption { } } +// WithCredentials sets tye id and secret func WithCredentials(id, secret string) TokenOption { return func(o *TokenOptions) { o.ID = id @@ -198,12 +207,14 @@ func WithCredentials(id, secret string) TokenOption { } } +// WithToken sets the refresh token func WithToken(rt string) TokenOption { return func(o *TokenOptions) { o.RefreshToken = rt } } +// WithTokenIssuer sets the token issuer option func WithTokenIssuer(iss string) TokenOption { return func(o *TokenOptions) { o.Issuer = iss @@ -225,39 +236,55 @@ func NewTokenOptions(opts ...TokenOption) TokenOptions { return options } +// VerifyOptions struct type VerifyOptions struct { Context context.Context Namespace string } +// VerifyOption func type VerifyOption func(o *VerifyOptions) +// VerifyContext pass context to verify func VerifyContext(ctx context.Context) VerifyOption { return func(o *VerifyOptions) { o.Context = ctx } } + +// VerifyNamespace sets thhe namespace for verify func VerifyNamespace(ns string) VerifyOption { return func(o *VerifyOptions) { o.Namespace = ns } } +// RulesOptions struct type RulesOptions struct { Context context.Context Namespace string } +// RulesOption func type RulesOption func(o *RulesOptions) +// RulesContext pass rules context func RulesContext(ctx context.Context) RulesOption { return func(o *RulesOptions) { o.Context = ctx } } +// RulesNamespace sets the rule namespace func RulesNamespace(ns string) RulesOption { return func(o *RulesOptions) { o.Namespace = ns } } + +// Logger sets the logger +func Logger(l logger.Logger) Option { + return func(o *Options) { + o.Logger = l + } +} diff --git a/broker/options.go b/broker/options.go index 603f281f..5b7d2390 100644 --- a/broker/options.go +++ b/broker/options.go @@ -13,9 +13,11 @@ import ( type Options struct { Addrs []string Secure bool - Codec codec.Codec - // Logger + // Codec + Codec codec.Codec + + // Logger the logger Logger logger.Logger // Handler executed when errors occur processing messages ErrorHandler Handler diff --git a/config/options.go b/config/options.go index 1192ecb5..9e87f391 100644 --- a/config/options.go +++ b/config/options.go @@ -28,6 +28,7 @@ type Option func(o *Options) func NewOptions(opts ...Option) Options { options := Options{ + Logger: logger.DefaultLogger, Context: context.Background(), } for _, o := range opts { diff --git a/network/transport/options.go b/network/transport/options.go index b04d9c4c..4c788be9 100644 --- a/network/transport/options.go +++ b/network/transport/options.go @@ -24,7 +24,7 @@ type Options struct { TLSConfig *tls.Config // Timeout sets the timeout for Send/Recv Timeout time.Duration - // Logger + // Logger sets the logger Logger logger.Logger // Other options for implementations of the interface // can be stored in a context diff --git a/registry/options.go b/registry/options.go index 08f37c86..1c283b2e 100644 --- a/registry/options.go +++ b/registry/options.go @@ -13,7 +13,9 @@ type Options struct { Timeout time.Duration Secure bool TLSConfig *tls.Config - Logger logger.Logger + + // Logger imp + Logger logger.Logger // Other options for implementations of the interface // can be stored in a context Context context.Context diff --git a/store/options.go b/store/options.go index 92f8a91c..3eac5231 100644 --- a/store/options.go +++ b/store/options.go @@ -17,7 +17,7 @@ type Options struct { Database string // Table is analag for a table in database backends or a key prefix in KV backends Table string - // Logger + // Logger the logger Logger logger.Logger // Context should contain all implementation specific options, using context.WithValue. Context context.Context diff --git a/tracer/options.go b/tracer/options.go index 33e90fd1..29fbbdc2 100644 --- a/tracer/options.go +++ b/tracer/options.go @@ -1,5 +1,7 @@ package tracer +import "github.com/unistack-org/micro/v3/logger" + var ( // DefaultSize of the buffer DefaultSize = 64 @@ -7,6 +9,8 @@ var ( // Options struct type Options struct { + // Logger is the logger for messages + Logger logger.Logger // Size is the size of ring buffer Size int } @@ -30,10 +34,18 @@ func ReadTrace(t string) ReadOption { } } +// Logger sets the logger +func Logger(l logger.Logger) Option { + return func(o *Options) { + o.Logger = l + } +} + // NewOptions returns default options func NewOptions(opts ...Option) Options { options := Options{ - Size: DefaultSize, + Logger: logger.DefaultLogger, + Size: DefaultSize, } for _, o := range opts { o(&options)