// expandPreferences checks each preference if it contains a variable "${...}" if it finds one
// it will check that this variable has been defined and fills it accordingly. If a string contains
// a variable that is not defined an error is returned.
expandPreferences checks each preference if it contains a variable "${...}" if it finds one
it will check that this variable has been defined and fills it accordingly. If a string contains
a variable that is not defined an error is returned.
// expandPreferences checks each preference if it contains a variable " $ { ... } " if it finds one // it will check that this variable has been defined and fills it accordingly . If a string contains // a variable that is not defined an error is returned .
func expandPreferences(preferences map[string]interface{}, variables map[string]string) (expandedPreferences map[string]interface{}, err error) {
	expandedPreferences = make(map[string]interface{})
	for key, value := range preferences {
		switch value.(type) {
		default:
			log.Println("Unknown preference type in config")
		case []interface{}:
			for k, v := range value.([]interface{}) {
				value.([]interface{})[k], err = expandVariable(v.(string), variables)
				if err != nil {
					return expandedPreferences, err
				}
			}
			expandedPreferences[key] = value
		case interface{}:
			if _, ok := value.(string); ok {
				expandedPreferences[key], err = expandVariable(value.(string), variables)
				if err != nil {
					return expandedPreferences, err
				}
			} else if _, ok := value.(bool); ok {
				expandedPreferences[key] = value
			} else if _, ok := value.(int); ok {
				expandedPreferences[key] = value
			}
		}
	}
	return expandedPreferences, nil
}
func expandPreferences ( preferences map [ string ] interface { } , variables map [ string ] string ) ( expandedPreferences map [ string ] interface { } , err error ) { expandedPreferences = make ( map [ string ] interface { } ) for key , value := range preferences { switch value . ( type ) { default : log . Println ( " " ) case [ ] interface { } : for k , v := range value . ( [ ] interface { } ) { value . ( [ ] interface { } ) [ k ] , err = expandVariable ( v . ( string ) , variables ) if err != nil { return expandedPreferences , err } } expandedPreferences [ key ] = value case interface { } : if _ , ok := value . ( string ) ; ok { expandedPreferences [ key ] , err = expandVariable ( value . ( string ) , variables ) if err != nil { return expandedPreferences , err } } else if _ , ok := value . ( bool ) ; ok { expandedPreferences [ key ] = value } else if _ , ok := value . ( int ) ; ok { expandedPreferences [ key ] = value } } } return expandedPreferences , nil }
expandPreferences checks each preference if it contains a variable "${...}" if it finds one
it will check that this variable has been defined and fills it accordingly.
expandPreferences checks each preference if it contains a variable " $ { ... } " if it finds one it will check that this variable has been defined and fills it accordingly .
// FIXME: Add check to handle empty preferences map // A slice has to be handled differently than a map // For an array // For a single field // Handle string variables (Only string variables can be expanded) // Handle bool variables // Handle int variables