Skip to content

Commit

Permalink
Merge pull request #62 from unistack-org/master
Browse files Browse the repository at this point in the history
merge stable
  • Loading branch information
vtolstov authored Nov 18, 2021
2 parents 332803d + b9bbfdf commit 07c9304
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 212 deletions.
30 changes: 30 additions & 0 deletions config/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,33 @@ func SetOption(k, v interface{}) Option {
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)
}
}

// SetWatchOption returns a function to setup a context with given value
func SetWatchOption(k, v interface{}) WatchOption {
return func(o *WatchOptions) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}
4 changes: 3 additions & 1 deletion config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type LoadOptions struct {
Struct interface{}
Override bool
Append bool
Context context.Context
}

func NewLoadOptions(opts ...LoadOption) LoadOptions {
Expand Down Expand Up @@ -102,7 +103,8 @@ type SaveOption func(o *SaveOptions)

// SaveOptions struct
type SaveOptions struct {
Struct interface{}
Struct interface{}
Context context.Context
}

// SaveStruct override struct for save to config
Expand Down
Loading

0 comments on commit 07c9304

Please sign in to comment.