MCPcopy Create free account
hub / github.com/DoNewsCode/core / Example

Function Example

config/remote/etcd/example_test.go:16–39  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14)
15
16func 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
41func put(cfg clientv3.Config, key, val string) error {
42 client, err := clientv3.New(cfg)

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
WithKeyFunction · 0.92
ProvideEssentialsMethod · 0.80
putFunction · 0.70
StringMethod · 0.65

Tested by

no test coverage detected