diff --git a/config/source/memory/options.go b/config/source/memory/options.go index 5b1e6c57..98328cc1 100644 --- a/config/source/memory/options.go +++ b/config/source/memory/options.go @@ -3,11 +3,23 @@ package memory import ( "context" - "github.com/micro/go-micro/config/source" + "github.com/micro/go-config/source" ) type changeSetKey struct{} +func withData(d []byte, f string) source.Option { + 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, + }) + } +} + // WithChangeSet allows a changeset to be set func WithChangeSet(cs *source.ChangeSet) source.Option { return func(o *source.Options) { @@ -18,15 +30,12 @@ func WithChangeSet(cs *source.ChangeSet) source.Option { } } -// WithData allows the source data to be set -func WithData(d []byte) source.Option { - 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: "json", - }) - } +// 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") }