nanoconf

package module
v0.0.0-...-663038e Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 9 Imported by: 6

README

go-nanoconf

Extremely minimalistic library for reading YAML configuration. In fact, it basically just reads YAML into a map of string/object and has few little helpers to fetch the data.

If you need arduous, spaciously ample embelishments, check out Viper instead.

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
}

func NewConfig

func NewConfig(cfgpath string) *Config

func (*Config) Find

func (cfg *Config) Find(levelPath string) *Inspector

Find returns a context of the tree config. Each YAML-based config is basically a tree. So Find resets the root of the tree to a specific point.

func (*Config) Root

func (cfg *Config) Root() *Inspector

GetContent returns a content of the configuration

func (*Config) SetSeparator

func (cfg *Config) SetSeparator(sep string) *Config

SetSeparator sets a separator for Find path. Default is ":".

type Inspector

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

func NewInspector

func NewInspector(tree *map[string]interface{}) *Inspector

func (*Inspector) DefaultInt

func (ins *Inspector) DefaultInt(val string, overlay string, defaultValue int) int

DefaultInt is a wrapper around Int method, allowing return default value, in case nothing has been found. Overlay value is an empty string and it doesn't mean 0, but nil.

func (*Inspector) Int

func (ins *Inspector) Int(key string, overlay string) (int, error)

Int returns an integer type of a config value.

func (*Inspector) Raw

func (ins *Inspector) Raw() map[string]interface{}

Return the entire tree raw

func (*Inspector) String

func (ins *Inspector) String(key string, overlay string) string

String returns a string type of a config value.

type NanoconfFinder

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

func NewNanoconfFinder

func NewNanoconfFinder(appname string) *NanoconfFinder

Constructor

func (*NanoconfFinder) AddName

func (nf *NanoconfFinder) AddName(name string) *NanoconfFinder

AddName adds a name to the stack

func (*NanoconfFinder) AddPath

func (nf *NanoconfFinder) AddPath(cfgpath string) *NanoconfFinder

AddPath adds a path to the stack

func (*NanoconfFinder) CleanNames

func (nf *NanoconfFinder) CleanNames() *NanoconfFinder

CleanNames removes all the names from the stack

func (*NanoconfFinder) CleanPaths

func (nf *NanoconfFinder) CleanPaths() *NanoconfFinder

CleanPaths removes all the paths from the stack

func (*NanoconfFinder) DefaultSetup

func (nf *NanoconfFinder) DefaultSetup(usr *user.User) *NanoconfFinder

Setup typical locations for the user: /etc, $HOME/.config..., $HOME/.<cfg> etc. If user is nil, current user is used.

func (*NanoconfFinder) FindAll

func (nf *NanoconfFinder) FindAll() []string

FindAll finds all possible configuration files that would match the search.

func (*NanoconfFinder) FindDefault

func (nf *NanoconfFinder) FindDefault() string

FindDefault returns assumed confguration that could be default, unless it is pre-set.

func (*NanoconfFinder) FindFirst

func (nf *NanoconfFinder) FindFirst() string

FindFirst finds nearest configuration that matches the search

func (*NanoconfFinder) SetDefaultConfig

func (nf *NanoconfFinder) SetDefaultConfig(cfgpath string) *NanoconfFinder

Jump to

Keyboard shortcuts

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