goconfig: github.com/crgimenes/goconfig Index | Examples | Files | Directories

package goconfig

import "github.com/crgimenes/goconfig"

Package goconfig uses a struct as input and populates the fields of this struct with parameters fom command line, environment variables and configuration file.

Index

Examples

Package Files

config.go doc.go

Variables

var ErrFileFormatNotDefined = errors.New("file format not defined")

ErrFileFormatNotDefined Is the error that is returned when there is no defined configuration file format.

var File string

File name of default config file

var FileEnv string

FileEnv is the enviroment variable that define the config file

var FileRequired bool

FileRequired config file required

var Formats []Fileformat

Formats is the list of registered formats.

var HelpString string

HelpString temporarily saves help

var Path string

Path sets default config path

var PathEnv string

PathEnv is the enviroment variable that define the config file path

var PrefixEnv string

PrefixEnv is a string that would be placed at the beginning of the generated Event tags.

var PrefixFlag string

PrefixFlag is a string that would be placed at the beginning of the generated Flag tags.

var Tag = "cfg"

Tag to set main name of field

var TagDefault = "cfgDefault"

TagDefault to set default value

var TagHelper = "cfgHelper"

TagHelper to set usage help line

var Usage func()

Usage is a function to show the help, can be replaced by your own version.

var WatchConfigFile bool

WatchConfigFile is the flag to update the config when the config file changes

func DefaultUsage Uses

func DefaultUsage()

DefaultUsage is assigned for Usage function by default

func Parse Uses

func Parse(config interface{}) (err error)

Parse configuration

Code:


type config struct {
    Name  string `cfg:"Name" cfgDefault:"root"`
    Value int    `cfg:"Value" cfgDefault:"123"`
}

cfg := config{}

err := Parse(&cfg)
if err != nil {
    println(err)
}

println("Name:", cfg.Name, "Value:", cfg.Value)

func ParseAndWatch Uses

func ParseAndWatch(config interface{}) (chChanges chan int64, chErr chan error, err error)

ParseAndWatch configuration returns a channel for errors while watching files and anorther when each update has been detected

func PrintDefaults Uses

func PrintDefaults()

PrintDefaults print the default help

type Fileformat Uses

type Fileformat struct {
    Extension   string
    Load        func(config interface{}) (err error)
    PrepareHelp func(config interface{}) (help string, err error)
}

Fileformat struct holds the functions to Load the file containing the settings

Directories

PathSynopsis
goenv
goflags
hcl
helper
ini
json
structtag
toml
validate
yaml

Package goconfig imports 11 packages (graph) and is imported by 14 packages. Updated 2019-10-14. Refresh now. Tools for package owners.