config: add logger to options

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-12-07 19:27:08 +03:00
parent c7ed807129
commit 8fd745eab0

View File

@ -4,17 +4,20 @@ import (
"context"
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger"
)
type Options struct {
BeforeLoad []func(context.Context, Config) error
AfterLoad []func(context.Context, Config) error
AfterLoad []func(context.Context, Config) error
BeforeSave []func(context.Context, Config) error
AfterSave []func(context.Context, Config) error
AfterSave []func(context.Context, Config) error
// Struct that holds config data
Struct interface{}
// struct tag name
StructTag string
// logger that will be used
Logger logger.Logger
// codec that used for load/save
Codec codec.Codec
// for alternative data
@ -54,12 +57,10 @@ func BeforeSave(fn ...func(context.Context, Config) error) Option {
func AfterSave(fn ...func(context.Context, Config) error) Option {
return func(o *Options) {
o.AfterSave= fn
o.AfterSave = fn
}
}
func Context(ctx context.Context) Option {
return func(o *Options) {
o.Context = ctx
@ -73,7 +74,13 @@ func Codec(c codec.Codec) Option {
}
}
// Struct
func Logger(l logger.Logger) Option {
return func(o *Options) {
o.Logger = l
}
}
// Struct used as config
func Struct(v interface{}) Option {
return func(o *Options) {
o.Struct = v