Exemplo n.º 1
0
func (p *prefixParserLoader) loadPossibleEnvironmentVariable(envVar string) (config.Key, string) {
	equalIndex := strings.Index(envVar, Equal)
	key, value := envVar[:equalIndex], envVar[equalIndex+1:]
	if !strings.HasPrefix(key, p.prefix) {
		return config.Key(nil), ""
	}
	key = strings.TrimPrefix(key, p.prefix)
	return p.parser.Parse(key), value
}
Exemplo n.º 2
0
//LoadReader uses l's settings and a encoding/json.Decoder to parse Values from in.
//If the call to encoding/json.Decoder.Decode() returns an error, then that error
//is returned with nil *Values.
//in must represent a JSON encoded object. Any other type will error.
//
//Notice that LoadReader is a config.ReaderFuncLoader and it is used in this manner
//in the examples.
func (l *Loader) LoadReader(in io.Reader) (*config.Values, error) {
	object, err := parseJson(in)
	if err != nil {
		return nil, err
	}
	values := config.NewValues()
	l.loadMapIntoValues(config.Key(nil), values, object)
	return values, nil
}