config/config.go
func LoadFromEnv(v interface{}, prefix string) (result []MarshalledEnvironmentVar) {
	pointerValue := reflect.ValueOf(v)
	structValue := pointerValue.Elem()
	structType := structValue.Type()

	for i := 0; i < structValue.NumField(); i++ {
		structField := structType.Field(i)
		fieldValue := structValue.Field(i)

		if fieldValue.CanSet() {
			envKey := strings.ToUpper(prefix) + gocase.ToUpperSnake(structField.Name)
			envVal := os.Getenv(envKey)

			if envVal != "" {
				// create a json blob with the env data
				jsonStr := ""
				if fieldValue.Kind() == reflect.String {
					jsonStr = fmt.Sprintf(`{"%s": "%s"}`, structField.Name, envVal)
				} else {
					jsonStr = fmt.Sprintf(`{"%s": %s}`, structField.Name, envVal)
				}

				err := json.Unmarshal([]byte(jsonStr), v)
				result = append(result, MarshalledEnvironmentVar{envKey, envVal, structField.Name, err})
			}
		}
	}

	return
}
func LoadFromEnv(v interface{}, prefix string) (result []MarshalledEnvironmentVar) {
	pointerValue := reflect.ValueOf(v)
	structValue := pointerValue.Elem()
	structType := structValue.Type()

	for i := 0; i < structValue.NumField(); i++ {
		structField := structType.Field(i)
		fieldValue := structValue.Field(i)

		if fieldValue.CanSet() {
			envKey := strings.ToUpper(prefix) + gocase.ToUpperSnake(structField.Name)
			envVal := os.Getenv(envKey)

			if envVal != "" {
				// create a json blob with the env data
				jsonStr := ""
				if fieldValue.Kind() == reflect.String {
					jsonStr = fmt.Sprintf(`{"%s": "%s"}`, structField.Name, envVal)
				} else {
					jsonStr = fmt.Sprintf(`{"%s": %s}`, structField.Name, envVal)
				}

				err := json.Unmarshal([]byte(jsonStr), v)
				result = append(result, MarshalledEnvironmentVar{envKey, envVal, structField.Name, err})
			}
		}
	}

	return
}
func LoadFromEnv ( v interface { } , prefix string ) ( result [ ] MarshalledEnvironmentVar ) { pointerValue := reflect . ValueOf ( v ) structValue := pointerValue . Elem ( ) structType := structValue . Type ( ) for i := 0 ; i < structValue . NumField ( ) ; i ++ { structField := structType . Field ( i ) fieldValue := structValue . Field ( i ) if fieldValue . CanSet ( ) { envKey := strings . ToUpper ( prefix ) + gocase . ToUpperSnake ( structField . Name ) envVal := os . Getenv ( envKey ) if envVal != " " { // create a json blob with the env data jsonStr := " " if fieldValue . Kind ( ) == reflect . String { jsonStr = fmt . Sprintf ( `{"%s": "%s"}` , structField . Name , envVal ) } else { jsonStr = fmt . Sprintf ( `{"%s": %s}` , structField . Name , envVal ) } err := json . Unmarshal ( [ ] byte ( jsonStr ) , v ) result = append ( result , MarshalledEnvironmentVar { envKey , envVal , structField . Name , err } ) } } } return }
// LoadFromEnv iterates through a
// struct's fields and tries to find matching
// environment variables.
// Returns a map of environment key and values that were
// successfully set into the struct
LoadFromEnv iterates through a struct s fields and tries to find matching environment variables . Returns a map of environment key and values that were successfully set into the struct