Documentation ¶
Overview ¶
Code is taken from github.com/caarlos0/env and modified to handle JSON values for examples, please visit the github repo
Package config provides Settings interface for accessing Predix environment variables. The values can be boolean, number, string, or JSON object.
An example shell script for defining and setting a json as value is given here. you can read the JSON or any part of it by providing the environment name as key and the list of object names and array indexes as the path to the value.
e.g. for MY_ENV defined below, Settings.GetEnv("MY_ENV", "array", "1") will return "b"
#!/usr/bin/env bash # function define(){ IFS='\n' read -r -d '' ${1} || true; } # export value="this is a value" # define MY_ENV << JSON { "home": "$HOME", "array": ["a", "b", "c"], "pwd": "`pwd`" } JSON # export MY_ENV
Index ¶
- Variables
- func Parse(v interface{}) error
- type Settings
- func (r Settings) GetBoolEnv(name string, path ...string) bool
- func (r Settings) GetEnv(name string, path ...string) interface{}
- func (r Settings) GetIntEnv(name string, path ...string) int
- func (r Settings) GetService(names ...string) interface{}
- func (r Settings) GetStringEnv(name string, path ...string) string
- func (r Settings) Parse(v interface{}) error
- func (r Settings) PostgresUri(a ...string) string
- func (r Settings) RabbitmqUri(a ...string) string
- func (r *Settings) RedisService(a ...string) interface{}
- func (r Settings) ServiceUri(names ...string) string
- func (r Settings) String() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotAStructPtr is returned if you pass something that is not a pointer to a // Struct to Parse ErrNotAStructPtr = errors.New("Expected a pointer to a Struct") // ErrUnsupportedType if the struct field type is not supported by env ErrUnsupportedType = errors.New("Type is not supported") // ErrUnsupportedSliceType if the slice element type is not supported by env ErrUnsupportedSliceType = errors.New("Unsupported slice type") )
Functions ¶
Types ¶
type Settings ¶
func AppSettings ¶
func AppSettings() *Settings
func NewSettings ¶
func NewSettings() *Settings
func (Settings) GetBoolEnv ¶
GetEnv returns env boolean value for the given name. If the value is JSON and path is provided, return the part specified.
func (Settings) GetEnv ¶
GetEnv returns env value for the given name. If the value is JSON and path is provided, return the part specified.
func (Settings) GetIntEnv ¶
GetEnv returns env int value for the given name. If the value is JSON and path is provided, return the part specified.
func (Settings) GetService ¶
GetService looks up by name and then by label and returns the service from VCAP_SERVICES environment variable
func (Settings) GetStringEnv ¶
GetEnv returns env string value for the given name. If the value is JSON and path is provided, return the part specified.
func (Settings) PostgresUri ¶
func (Settings) RabbitmqUri ¶
func (*Settings) RedisService ¶
func (Settings) ServiceUri ¶
ServiceUri looks up by name and then by label and returns service uri from the VCAP_SERVICES environment variable