config

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

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 10 Imported by: 0

README

config

License GoDoc

The config is go configuration module. It is:

  • Simple

  • Winbase api style, like GetProfileString, GetProfileInt ...

  • Stored in JSON, INI, TOML format.

  • Overridable by environment variable and arguments.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DELIMITER string = "/"

Functions

This section is empty.

Types

type Config

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

func New

func New(dsn string) *Config

New return a configure store with map stored and file stored. And it detects file format by file name extension. JSON and TOML are supported now. Otherwise, return error.

func (*Config) Arg

func (c *Config) Arg() map[string]interface{}

Arg returns the map of arguments.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone a new config

func (*Config) Data

func (c *Config) Data() map[string]interface{}

Data returns the clone of config data.

func (*Config) Env

func (c *Config) Env() map[string]interface{}

Env returns the map of env. variable.

func (*Config) Flatten

func (c *Config) Flatten() map[string]interface{}

Flatten returns the clone of config flatten map.

func (*Config) GetSection

func (c *Config) GetSection(section string) map[string]interface{}

func (*Config) GetSectionNames

func (c *Config) GetSectionNames() []string

func (*Config) GetValue

func (c *Config) GetValue(section string, key string, i interface{}) interface{}

func (*Config) HasKey

func (c *Config) HasKey(section string, key string) (interface{}, bool)

func (*Config) HasSection

func (c *Config) HasSection(section string) (map[string]interface{}, bool)

func (*Config) Load

func (c *Config) Load() (map[string]interface{}, error)

Load config data from file. Returns old data and error.

func (*Config) Save

func (c *Config) Save() error

Save config data to file.

func (*Config) SetArg

func (c *Config) SetArg(in map[string]string, replacer *strings.Replacer)

SetArg sets the map of arguments. It scans and filters all env. variable by reference mas.

func (*Config) SetEnv

func (c *Config) SetEnv(prefixes []string, replacer *strings.Replacer)

SetEnv sets the map of env. variable. It scans and filters all env. variable by prefix string and reference mas.

PREFIX_SECTION.KEY	SetEnv([]string{"PREFIX_"}, strings.NewReplacer(".", config.DELIMITER))

func (*Config) WriteSection

func (c *Config) WriteSection(section string, m map[string]interface{})

func (*Config) WriteValue

func (c *Config) WriteValue(section string, key string, i interface{})

type Store

type Store interface {

	// Existed returns true if the file was persisted.
	Existed() (bool, error)

	// Remove removes persisted configuration file.
	Remove() error

	// String describes the backing store for the config.
	String() string

	// Close cleans up resources associated with the store.
	Close() error
	// contains filtered or unexported methods
}

func NewStore

func NewStore(dsn string) Store

Jump to

Keyboard shortcuts

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