Created
October 8, 2022 20:24
-
-
Save by-sabbir/1a82a7230d327bd40e6978c6319d7b16 to your computer and use it in GitHub Desktop.
Revisions
-
by-sabbir created this gist
Oct 8, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,38 @@ package consul import ( "log" "github.com/hashicorp/consul/api" ) type KVClient struct { *api.KV } func NewKVClient(c *ConsulClient) *KVClient { return &KVClient{ c.KV(), } } func (k *KVClient) PutKV(key, value string) error { p := &api.KVPair{Key: key, Value: []byte(value)} _, err := k.Put(p, nil) if err != nil { log.Println("error instergin KV: ", err) return err } return nil } func (k *KVClient) GetKV(key string) (string, error) { p, _, err := k.Get(key, nil) if err != nil { log.Println("error getting value from key: ", err) return "", nil } return string(p.Value), nil }