Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDecodeFailed is given when the config cannot be decoded. ErrDecodeFailed = errConfig.Code("decode_fail").Error("failed to decode config") // ErrEncodeFailed is given when the config cannot be encoded. ErrEncodeFailed = errConfig.Code("encode_fail").Error("failed to encode config") // ErrFileNotFound is given when the config file cannot be found. ErrFileNotFound = errConfig.Code("not_found").Error("config file not found") // ErrTypeNotSet is given when a config has no type specified ErrTypeNotSet = errConfig.Code("type_not_set").Error("field `type` of config is not set") )
var (
// ErrVersionNotReachable is given when the migrater cannot reach the desired version
ErrVersionNotReachable = errConfig.Code("not_reachable").Error("desired config version not reachable")
)
Functions ¶
func ParseMap ¶
ParseMap uses mapstructure to convert a ConfigMap into a struct
For example, the following JSON:
{
"ssh_key": "/home/joris/.ssh/secrethub"
}
Can be loaded in a struct of type:
type UserConfig struct {
SSHKeyPath string `json:"ssh_key,omitempty"`
}
decodeHook is used to convert non-standard types into the correct format
func ReadFromFile ¶
ReadFromFile attempts to read a config as a struct from a file. It will unmarshal yaml and json into the destination.
func WriteToFile ¶
WriteToFile attempts to marshal the src arg and write to a file at the given path. If the file is of an unsupported extension we cannot determine what type of encoding to use, so it defaults to writing encoded json to that file. JSON is written in indented 'pretty' format to allow for easy user editing.
Types ¶
type ConfigMap ¶
type ConfigMap map[string]interface{}
ConfigMap is the type used for configurations that are still in a map format Map format is to make changes in structure with migrations possible
func MigrateConfigTo ¶
func MigrateConfigTo(io ui.IO, config ConfigMap, versionFrom int, versionTo int, migrations []Migration, checkOnly bool) (ConfigMap, error)
MigrateConfigTo attempts to convert a config in ConfigMap format from versionFrom to versionTo A list of Migrations has to be passed that form at least a path from versionFrom to versionTo Function may fail if the migration path contains dead ends that do not lead to versionTo Setting checkOnly to true will not perform the actual migration and can be used to check whether there is a valid migration path from one version to another
func ReadConfigurationDataFromFile ¶
ReadConfigurationDataFromFile retrieves the data and attempts to read the config as a ConfigMap from a file. This simplifies the process of determining to parse the config as a ConfigMap or to directly unmarshal into a struct.
func ReadMap ¶
ReadMap attempts to unmarshal a []byte it into the dest map. Both json and yaml are supported
func (ConfigMap) GetType ¶
GetType returns the type of the configuration file If it is not set, it is assumed to have no type.
func (ConfigMap) GetVersion ¶
GetVersion returns the version of the configuration file. If it is not set, it is assumed that is configuration version 1.