Beispiel #1
0
func Map(config interface{}) map[string]interface{} {
	fields := internal.NewFields(config)
	result := map[string]interface{}{}
	for name, field := range fields {
		result[name] = field.Value.Interface()
	}
	return result
}
Beispiel #2
0
func String(config interface{}) string {
	fields := internal.NewFields(config)
	buffer := []string{}
	for name, field := range fields {
		value, _ := json.Marshal(field.Value.Interface())
		buffer = append(buffer, fmt.Sprintf("%s=%s", name, value))
	}
	return strings.Join(buffer, ", ")
}
Beispiel #3
0
func FromEnviron(config interface{}, environ []string) {
	fields := internal.NewFields(config)
	tags := fields.Tags("env")
	values := internal.NewEnviron(environ)
	update := map[string]interface{}{}
	for name := range fields {
		if tag, ok := tags[name]; ok {
			if value, ok := values[tag]; ok {
				update[name] = value
			}
		}
	}
	internal.Decode(update, config)
}