forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.go
46 lines (38 loc) · 1.01 KB
/
database.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package env
import (
"fmt"
"os"
"strings"
"github.com/kelseyhightower/confd/builtin/databases/env/util"
"github.com/kelseyhightower/confd/log"
)
// Client provides a shell for the env client
type Client struct{}
// NewEnvClient returns a new client
func NewEnvClient() (*Client, error) {
return &Client{}, nil
}
// GetValues queries the environment for keys
func (c *Client) GetValues(keys []string) (map[string]string, error) {
allEnvVars := os.Environ()
envMap := make(map[string]string)
for _, e := range allEnvVars {
index := strings.Index(e, "=")
envMap[e[:index]] = e[index+1:]
}
vars := make(map[string]string)
for _, key := range keys {
k := util.Transform(key)
for envKey, envValue := range envMap {
if strings.HasPrefix(envKey, k) {
vars[util.Clean(envKey)] = envValue
}
}
}
log.Debug(fmt.Sprintf("Key Map: %#v", vars))
return vars, nil
}
func (c *Client) WatchPrefix(prefix string, keys []string, waitIndex uint64, stopChan chan bool) (uint64, error) {
<-stopChan
return 0, nil
}