Documentation ¶
Overview ¶
Package config is used for managing configuration settings used by the app.
Index ¶
Constants ¶
const ( // DefaultConfigFolder is the name of the config folder in the user's home directory. DefaultConfigFolder = ".json-exec" // DefaultConfigName is the default configuration file name without an extension. DefaultConfigName = "json-exec" // DefaultLogLevel is the default logging level. DefaultLogLevel = zerolog.InfoLevel // LogLevelFieldName is the name of the level field in log messages. DefaultLogLevelFieldName = "@level" // LogMessageFieldName is the name of the message field in log messages. DefaultLogMessageFieldName = "@message" // LogTimestampFieldName is the name of the timestamp field in log messages. DefaultLogTimestampFieldName = "@timestamp" // EnvPrefix is the prefix used for configuration via environment variables. EnvPrefix = "JSON_EXEC" )
Variables ¶
This section is empty.
Functions ¶
func Load ¶
Load simply loads settings from the config file.
The file must be a valid YAML-formatted file and must have a .yaml or .yml extension.
The following order of precedence is used in determining the path to the config file:
- the value passed to this function if it is not empty
- the value of the prefixed CONFIG_FILE environment variable (this is the EnvPrefix followed by an underscore followed by CONFIG_FILE)
- the default configuration file
The following order of precedence is used to determine the location of the default config file:
- the current working directory
- the default configuration directory inside the user's home directory
If a configuration file is specified explicitly and that file does not exist, this function will return an error. If one is not specified and the default configuration file cannot be found, no error will be returned. Instead default values will be used for the configuration settings.
Types ¶
type AppConfig ¶
type AppConfig struct { // Global holds the global configuration settings. Global GlobalConfig `yaml:"global"` // Run holds the "run" command configuration settings. Run RunConfig `yaml:"run"` // Version holds the "version" command configuration settings. Version VersionConfig `yaml:"version"` }
AppConfig holds the configuration settings for the application.
type GlobalConfig ¶
type GlobalConfig struct { // ExtraFields is a mapping of extra fields to add to the output messages. ExtraFields map[string]string `yaml:"extra_fields"` // LevelFieldName contains the name of the level field. LevelFieldName string `yaml:"level_field_name"` // LogLevel contains the actual zerolog level for logging output messages. LogLevel zerolog.Level // LogLevelRaw represents the string version of the logging level. LogLevelRaw string `yaml:"log_level"` // MessageFieldName contains the name of the message field. MessageFieldName string `yaml:"message_field_name"` // TimestampFieldName contains the name of the timestamp field. TimestampFieldName string `yaml:"timestamp_field_name"` }
GlobalConfig contains the global options for the application.
func (*GlobalConfig) UnmarshalYAML ¶
func (c *GlobalConfig) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML decodes the raw YAML into the object.
It converts any raw values to their corresponding actual values and then performs validation on the object member values. It may set default values as well, if necessary.
type RunConfig ¶
type RunConfig struct { // IgnoreStderr indicates whether or not to ignore output from stderr. IgnoreStderr bool `yaml:"ignore_stderr"` // IgnoreStdout indicates whether or not to ignore output from stdout. IgnoreStdout bool `yaml:"ignore_stdout"` }
RunConfig contains the options for the "run" command.
type VersionConfig ¶
type VersionConfig struct { // Plaintext indicates whether or not to display the version information in plaintext. Plaintext bool `yaml:"plaintext"` // Verbose indicates whether or not build and release information should be printed along with the version. Verbose bool `yaml:"verbose"` }
VersionConfig contains the options for the "version" command.