micro/config/options.go
Vasiliy Tolstov 6d0d8c1de3 init config
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2020-12-03 22:58:05 +03:00

59 lines
898 B
Go

package config
import (
"context"
"github.com/unistack-org/micro/v3/codec"
)
type Options struct {
// Struct that holds config data
Struct interface{}
// struct tag name
StructTag string
// codec that used for load/save
Codec codec.Codec
// for alternative data
Context context.Context
}
type Option func(o *Options)
func NewOptions(opts ...Option) Options {
options := Options{
Context: context.Background(),
}
for _, o := range opts {
o(&options)
}
return options
}
func Context(ctx context.Context) Option {
return func(o *Options) {
o.Context = ctx
}
}
// Codec sets the source codec
func Codec(c codec.Codec) Option {
return func(o *Options) {
o.Codec = c
}
}
// Struct
func Struct(v interface{}) Option {
return func(o *Options) {
o.Struct = v
}
}
// StructTag
func StructTag(name string) Option {
return func(o *Options) {
o.StructTag = name
}
}