2019-05-31 01:11:13 +03:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/config/source"
|
2019-05-31 01:11:13 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type changeSetKey struct{}
|
|
|
|
|
2019-05-31 15:44:28 +03:00
|
|
|
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()
|
|
|
|
}
|
2019-05-31 15:44:28 +03:00
|
|
|
o.Context = context.WithValue(o.Context, changeSetKey{}, &source.ChangeSet{
|
|
|
|
Data: d,
|
|
|
|
Format: f,
|
|
|
|
})
|
2019-05-31 01:11:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-31 15:44:28 +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()
|
|
|
|
}
|
2019-05-31 15:44:28 +03:00
|
|
|
o.Context = context.WithValue(o.Context, changeSetKey{}, cs)
|
2019-05-31 01:11:13 +03:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 15:44:28 +03:00
|
|
|
|
2019-05-31 15:45:28 +03:00
|
|
|
// WithJSON allows the source data to be set to json
|
|
|
|
func WithJSON(d []byte) source.Option {
|
2019-05-31 15:44:28 +03:00
|
|
|
return withData(d, "json")
|
|
|
|
}
|
|
|
|
|
2019-05-31 15:45:28 +03:00
|
|
|
// WithYAML allows the source data to be set to yaml
|
|
|
|
func WithYAML(d []byte) source.Option {
|
2019-05-31 15:44:28 +03:00
|
|
|
return withData(d, "yaml")
|
|
|
|
}
|