config

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: MIT Imports: 13 Imported by: 0

README

gogitsu/config

Documentation

Overview

Package config implements configuration components of gogitsu lib.

Package config implements configuration components of gogitsu lib.

Package config implements configuration components of gogitsu lib.

Index

Constants

View Source
const (
	// TagEnv is the Name of the environment variable or a list of names
	TagEnv = "env"
	// TagEnvLayout is the Value parsing layout (for types like time.Time)
	TagEnvLayout = "env-layout"
	// TagEnvDefault is the Default value
	TagEnvDefault = "env-default"
	// TagEnvSeparator is the Custom list and map separator
	TagEnvSeparator = "env-separator"
	// TagEnvDescription is the Environment variable description
	TagEnvDescription = "env-description"
	// TagEnvRequired is the Flag to mark a field as required
	TagEnvRequired = "env-required"
)
View Source
const (
	// DefaultSeparator is a default list and map separator character
	DefaultSeparator = ","
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Configurator

type Configurator struct {
	// contains filtered or unexported fields
}

Configurator is the main struct to access configuration functionalities.

func NewConfigurator

func NewConfigurator() *Configurator

NewConfigurator returns a new Configurator instance. Here we not set a parser.

func NewConfiguratorFor

func NewConfiguratorFor(format string) *Configurator

NewConfiguratorFor returns a new Configurator with a configured parser for the input format.

func (*Configurator) FUsage

func (c *Configurator) FUsage(w io.Writer, cfg interface{}, headerText *string, usageFuncs ...func()) func()

FUsage prints configuration help into the custom output. Other usage instructions can be wrapped in and executed before this usage function

func (*Configurator) FileName

func (c *Configurator) FileName() string

FileName returns the configuration filename.

func (*Configurator) GetDescription

func (c *Configurator) GetDescription(cfg interface{}, headerText *string) (string, error)

GetDescription returns a description of environment variables. You can provide a custom header text.

func (*Configurator) Load

func (c *Configurator) Load(cfg interface{}) error

Load reads configuration from default file into the cfg structure.

func (*Configurator) LoadFromFile

func (c *Configurator) LoadFromFile(path string, cfg interface{}) error

LoadFromFile reads configuration from the specified file into the cfg structure.

func (*Configurator) Parser

func (c *Configurator) Parser() Parser

Parser returns the internal parser instance.

func (*Configurator) Usage

func (c *Configurator) Usage(cfg interface{}, headerText *string, usageFuncs ...func()) func()

Usage returns a configuration usage help. Other usage instructions can be wrapped in and executed before this usage function. The default output is STDERR.

func (*Configurator) WithEnvPrefix

func (c *Configurator) WithEnvPrefix(envPrefix string) *Configurator

WithEnvPrefix configure the env vars prefix.

func (*Configurator) WithFileNamePrefix

func (c *Configurator) WithFileNamePrefix(prefix string) *Configurator

WithFileNamePrefix .

func (*Configurator) WithFormat

func (c *Configurator) WithFormat(format string) *Configurator

WithFormat configure the internal Parser according to the input format.

func (*Configurator) WithParser

func (c *Configurator) WithParser(parser Parser) *Configurator

WithParser configure the internal Parser.

func (*Configurator) WithPath

func (c *Configurator) WithPath(path string) *Configurator

WithPath adds a path into the serach paths.

type ENVParser

type ENVParser struct{}

ENVParser will parse env from env file. It does not fill the struct, but set variables into the env.

func (*ENVParser) Parse

func (ep *ENVParser) Parse(r io.Reader, s interface{}) error

Parse parses variables from ENV into the input struct. It does not fill the struct, but set variables into the env.

type JSONParser

type JSONParser struct{}

JSONParser will parse env from json format.

func (*JSONParser) Parse

func (jp *JSONParser) Parse(r io.Reader, s interface{}) error

Parse parses variables from JSON into the input struct.

type Parser

type Parser interface {
	Parse(r io.Reader, s interface{}) error
}

Parser is the interface to define parsing functionality to read from a reader and parse values into a struct. A concrete Parser will read from the input "r" reader and parse values into the "s" struct using a concrete decoder.

func NewParser

func NewParser(format string) Parser

NewParser return a new Parser according to the config file format.

type Setter

type Setter interface {
	SetValue(string) error
}

Setter is an interface for a custom value setter.

To implement a custom value setter you need to add a SetValue function to your type that will receive a string raw value:

type MyField string

func (f *MyField) SetValue(s string) error {
	if s == "" {
		return fmt.Errorf("field value can't be empty")
	}
	*f = MyField("my field is: " + s)
	return nil
}

type TOMLParser

type TOMLParser struct{}

TOMLParser will parse env from toml format.

func (*TOMLParser) Parse

func (tp *TOMLParser) Parse(r io.Reader, s interface{}) error

Parse parses variables from TOML into the input struct. Here we skip returned metadata.

type YAMLParser

type YAMLParser struct{}

YAMLParser will parse env from yaml format.

func (*YAMLParser) Parse

func (yp *YAMLParser) Parse(r io.Reader, s interface{}) error

Parse parses variables from YAML into the input struct.

Jump to

Keyboard shortcuts

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