forked from kelseyhightower/confd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for env backend and new -backend flag
- Loading branch information
1 parent
9c384a3
commit e955a03
Showing
2 changed files
with
56 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
) | ||
|
||
var replacer = strings.NewReplacer("/", "_") | ||
|
||
// Client provides a wrapper around the consulkv 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]interface{}, error) { | ||
vars := make(map[string]interface{}) | ||
for _, key := range keys { | ||
k := transform(key) | ||
value := os.Getenv(k) | ||
if value != "" { | ||
vars[key] = value | ||
} | ||
} | ||
return vars, nil | ||
} | ||
|
||
func transform(key string) (string) { | ||
k := strings.TrimPrefix(key, "/") | ||
k = replacer.Replace(k) | ||
k = strings.ToUpper(k) | ||
return k | ||
} |