1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-12 08:23:58 +02:00
go-micro/plugins/config/source/runtimevar
2021-11-11 14:03:34 +00:00
..
go.mod upgrade to go 1.17 (#2346) 2021-11-11 14:03:34 +00:00
go.sum upgrade to go 1.17 (#2346) 2021-11-11 14:03:34 +00:00
options.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00
README.md add all the plugins 2020-12-26 15:32:45 +00:00
runtimevar.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00
watcher.go go-micro.dev/v4 (#2305) 2021-10-12 12:55:53 +01:00

Runtimevar Source

The runtimevar source is a source for the Go Cloud Development Kit runtimevar package.

This package takes a runtimevar.Variable and then allows you to use it as a backend source. When constructing your runtimevar.Variable, use the gocloud.dev/runtimevar.BytesDecoder decoder to allow your Snapshot value to be []byte. We then use the built in go-config encoder to decode the value. This defaults to json.

New Source

Specify a runtimevar source with the Go CDK runtimevar.Variable. It will panic if not specified.

// See https://godoc.org/gocloud.dev/runtimevar for examples on how to create
// a gocloud.dev/runtimevar.Varible. Use a BytesDecoder.
srv := runtimevar.NewSource(
	runtimevar.WithVariable(v),
)

Config Format

To load different runtimevar formats e.g yaml, toml, xml you must specify an encoder.

e := toml.NewEncoder()

src := runtimevar.NewSource(
        runtimevar.WithVariable(v),
	source.WithEncoder(e),
)

Load Source

Load the source into config

// Create new config
conf := config.NewConfig()

// Load runtimevar source
conf.Load(src)