config

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2017 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 - default value for flag "." represents current working directory

View Source
const DirFlag = "config-dir"

DirFlag used as flag name (see implementation in declareFlags()) It is used to define default directory where config files reside. This flag name is calculated 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 flag usage (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 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 (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 parse configuration for a plugin a store the results in data.
	// Argument data is a pointer to instance of a go structure.
	GetValue(data interface{}) (found bool, err error)

	// GetConfigName returns usually derived config name from plugin name:
	// flag = PluginName + FlagSuffix (evaluated most often a 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 to read it's configuration.

It tries to lookup `plugin + "-config"` in flags and declare the flag if it still not exists. It uses following opts. opts (used for defining 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