config: add helpers to load/save options (#60)
This commit is contained in:
parent
1829febb6e
commit
fbad257acc
@ -32,3 +32,23 @@ func SetOption(k, v interface{}) Option {
|
|||||||
o.Context = context.WithValue(o.Context, k, v)
|
o.Context = context.WithValue(o.Context, k, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetSaveOption returns a function to setup a context with given value
|
||||||
|
func SetSaveOption(k, v interface{}) SaveOption {
|
||||||
|
return func(o *SaveOptions) {
|
||||||
|
if o.Context == nil {
|
||||||
|
o.Context = context.Background()
|
||||||
|
}
|
||||||
|
o.Context = context.WithValue(o.Context, k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLoadOption returns a function to setup a context with given value
|
||||||
|
func SetLoadOption(k, v interface{}) LoadOption {
|
||||||
|
return func(o *LoadOptions) {
|
||||||
|
if o.Context == nil {
|
||||||
|
o.Context = context.Background()
|
||||||
|
}
|
||||||
|
o.Context = context.WithValue(o.Context, k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -66,6 +66,7 @@ type LoadOptions struct {
|
|||||||
Struct interface{}
|
Struct interface{}
|
||||||
Override bool
|
Override bool
|
||||||
Append bool
|
Append bool
|
||||||
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLoadOptions(opts ...LoadOption) LoadOptions {
|
func NewLoadOptions(opts ...LoadOption) LoadOptions {
|
||||||
@ -103,6 +104,7 @@ type SaveOption func(o *SaveOptions)
|
|||||||
// SaveOptions struct
|
// SaveOptions struct
|
||||||
type SaveOptions struct {
|
type SaveOptions struct {
|
||||||
Struct interface{}
|
Struct interface{}
|
||||||
|
Context context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// SaveStruct override struct for save to config
|
// SaveStruct override struct for save to config
|
||||||
|
Loading…
Reference in New Issue
Block a user