goconfig

package module
v0.0.0-...-5741386 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 4 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

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

Config is the main configuration struct

func New

func New(program string, sections ...Section) (*Config, error)

New creates a configuration with sections passed

func (*Config) Data

func (c *Config) Data(section string) Configurable

Data returns data from a section

func (*Config) Dump

func (c *Config) Dump() string

Dump returns data from a section

func (*Config) Load

func (c *Config) Load() error

Load configuration from defined file

func (*Config) LoadFromFile

func (c *Config) LoadFromFile(path string) error

LoadFromFile configuration from defined file

func (*Config) LoadIfFile

func (c *Config) LoadIfFile(path string) error

LoadIfFile try to load from path if not empty

func (*Config) PFlags

func (c *Config) PFlags()

PFlags register posix flags of the structs

type Configurable

type Configurable interface {
	//SetPFlags sets posix flags with the prefix and short options
	SetPFlags(short bool, prefix string)
	//BindViper must bind to viper instance pflags with the prefix
	BindViper(v *viper.Viper, prefix string)
	//BindViper must load values from viper instance
	FromViper(v *viper.Viper, prefix string)
	//Empty returns true if configuration is empty
	Empty() bool
	//Validate returns error if invalid value
	Validate() error
	//Dump returns string
	Dump() string
}

Configurable is the interface for configuration data

type Section

type Section struct {
	Name     string
	Required bool
	Short    bool
	Data     Configurable
}

Section represents configuration sections

Jump to

Keyboard shortcuts

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