github.com/micro/go-micro/v2@v2.9.1/config/source/etcd/README.md (about) 1 # Etcd Source 2 3 The etcd source reads config from etcd key/values 4 5 This source supports etcd version 3 and beyond. 6 7 ## Etcd Format 8 9 The etcd source expects keys under the default prefix `/micro/config` (prefix can be changed) 10 11 Values are expected to be JSON 12 13 ``` 14 // set database 15 etcdctl put /micro/config/database '{"address": "10.0.0.1", "port": 3306}' 16 // set cache 17 etcdctl put /micro/config/cache '{"address": "10.0.0.2", "port": 6379}' 18 ``` 19 20 Keys are split on `/` so access becomes 21 22 ``` 23 conf.Get("micro", "config", "database") 24 ``` 25 26 ## New Source 27 28 Specify source with data 29 30 ```go 31 etcdSource := etcd.NewSource( 32 // optionally specify etcd address; default to localhost:8500 33 etcd.WithAddress("10.0.0.10:8500"), 34 // optionally specify prefix; defaults to /micro/config 35 etcd.WithPrefix("/my/prefix"), 36 // optionally strip the provided prefix from the keys, defaults to false 37 etcd.StripPrefix(true), 38 ) 39 ``` 40 41 ## Load Source 42 43 Load the source into config 44 45 ```go 46 // Create new config 47 conf := config.NewConfig() 48 49 // Load file source 50 conf.Load(etcdSource) 51 ```