config

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config contains helper functions for parsing of configuration files.

Index

Constants

View Source
const DirDefault = "."

DirDefault holds a default value "." for flag, which represents current working directory.

View Source
const DirFlag = "config-dir"

DirFlag as flag name (see implementation in declareFlags()) is used to define default directory where config files reside. This flag name is derived from the name of the plugin.

View Source
const DirUsage = "Location of the configuration files; also set via 'CONFIG_DIR' env variable."

DirUsage used as a flag (see implementation in declareFlags()).

View Source
const EnvSuffix = "_CONFIG"

EnvSuffix is added to plugin name while loading plugins configuration from ENV variable.

View Source
const FlagSuffix = "-config"

FlagSuffix is added to plugin name while loading plugins configuration.

Variables

This section is empty.

Functions

func Dir added in v1.0.4

func Dir() (string, error)

Dir evaluates the flag DirFlag. It interprets "." as current working directory.

func ParseConfigFromYamlFile

func ParseConfigFromYamlFile(path string, cfg interface{}) error

ParseConfigFromYamlFile parses a configuration from a file in YAML format. The file's location is specified by the <path> parameter and the resulting config is stored into the structure referenced by the <cfg> parameter. If the file doesn't exist or cannot be read, the returned error will be of type os.PathError. An untyped error is returned in case the file doesn't contain a valid YAML configuration.

func SaveConfigToYamlFile

func SaveConfigToYamlFile(cfg interface{}, path string, perm os.FileMode, comment string) error

SaveConfigToYamlFile saves the configuration <cfg> into a YAML-formatted file at the location <path> with permissions defined by <perm>. <comment>, if non-empty, is printed at the beginning of the file before the configuration is printed (with a line break in between). Each line in <comment> should thus begin with the number sign ( # ). If the file cannot be created af the location, os.PathError is returned. An untyped error is returned if the configuration couldn't be marshaled into the YAML format.

Types

type PluginConfig

type PluginConfig interface {
	// GetValue parses configuration for a plugin and stores the results in data.
	// The argument data is a pointer to an instance of a go structure.
	GetValue(data interface{}) (found bool, err error)

	// GetConfigName returns config name derived from plugin name:
	// flag = PluginName + FlagSuffix (evaluated most often as absolute path to a config file)
	GetConfigName() string
}

PluginConfig is API for plugins to access configuration.

Aim of this API is to let a particular plugin to bind it's configuration without knowing a particular key name. The key name is injected in flavor (Plugin Name).

func ForPlugin

func ForPlugin(pluginName string, opts ...string) PluginConfig

ForPlugin returns API that is injectable to a particular Plugin and is used to read it's configuration.

It tries to lookup `plugin + "-config"` in flags and declare the flag if it still not exists. It uses the following opts (used to define flag (if it was not already defined)): - default value - usage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL