micro/config/source/memory/options.go

42 lines
887 B
Go
Raw Normal View History

2019-05-31 01:11:13 +03:00
package memory
import (
"context"
"github.com/micro/go-config/source"
2019-05-31 01:11:13 +03:00
)
type changeSetKey struct{}
func withData(d []byte, f string) source.Option {
2019-05-31 01:11:13 +03:00
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, &source.ChangeSet{
Data: d,
Format: f,
})
2019-05-31 01:11:13 +03:00
}
}
// WithChangeSet allows a changeset to be set
func WithChangeSet(cs *source.ChangeSet) source.Option {
2019-05-31 01:11:13 +03:00
return func(o *source.Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, changeSetKey{}, cs)
2019-05-31 01:11:13 +03:00
}
}
// WithJson allows the source data to be set to json
func WithJson(d []byte) source.Option {
return withData(d, "json")
}
// WithYaml allows the source data to be set to yaml
func WithYaml(d []byte) source.Option {
return withData(d, "yaml")
}