goconfig

package
v0.0.0-...-a54a33a Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: AGPL-3.0 Imports: 4 Imported by: 10

Documentation

Overview

Package goconfig provides a simple method for configuring applications.

This package is a work in progress and makes no API stability promises.

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. It uses Viper as configuration backend.

func New

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

New creates a new configuration with sections.

func (*Config) AddValidator

func (c *Config) AddValidator(v Validator)

AddValidator add custom validator to Config.

func (*Config) Data

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

Data returns a Configurable data section.

func (*Config) Dump

func (c *Config) Dump() string

Dump stored data.

func (*Config) Load

func (c *Config) Load() error

Load configuration from default files.

func (*Config) LoadFromFile

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

LoadFromFile configuration data.

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 of base section
	Name string
	// Required if can't be empty
	Required bool
	// Short if uses short flags
	Short bool
	// Data stores Configurable interface
	Data Configurable
}

Section stores Configurable objects.

type Validator

type Validator func(cfg *Config) error

Validator allows to define additional validators.

Jump to

Keyboard shortcuts

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