()
| 14 | ) |
| 15 | |
| 16 | func Example() { |
| 17 | addr := os.Getenv("ETCD_ADDR") |
| 18 | if addr == "" { |
| 19 | fmt.Println("set ETCD_ADDR for run example") |
| 20 | return |
| 21 | } |
| 22 | key := "core.yaml" |
| 23 | envEtcdAddrs := strings.Split(addr, ",") |
| 24 | ctx, cancel := context.WithTimeout(context.Background(), time.Second) |
| 25 | defer cancel() |
| 26 | cfg := clientv3.Config{ |
| 27 | Endpoints: envEtcdAddrs, |
| 28 | DialTimeout: time.Second, |
| 29 | Context: ctx, |
| 30 | } |
| 31 | _ = put(cfg, key, "name: etcd") |
| 32 | |
| 33 | c := core.New(etcd.WithKey(cfg, key, yaml.Codec{})) |
| 34 | c.ProvideEssentials() |
| 35 | fmt.Println(c.String("name")) |
| 36 | |
| 37 | // Output: |
| 38 | // etcd |
| 39 | } |
| 40 | |
| 41 | func put(cfg clientv3.Config, key, val string) error { |
| 42 | client, err := clientv3.New(cfg) |
nothing calls this directly
no test coverage detected