gocfg

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 8 Imported by: 5

README

gocfg

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GocfgTag = "cfg"
View Source
var GocfgValEnv = "env"
View Source
var GocfgValRequired = "required"

Functions

This section is empty.

Types

type Cfg

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

Cfg is an abstraction over a configuration

func New

func New(template interface{}) *Cfg

New returns a new *Cfg

func (*Cfg) Bool

func (c *Cfg) Bool(key string) (bool, bool)

Bool get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) BoolOr

func (c *Cfg) BoolOr(key string, defaultVal bool) bool

BoolOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Bools

func (c *Cfg) Bools() map[string]bool

func (*Cfg) Debug

func (c *Cfg) Debug()

Debug opens debug mode and prints more logs.

func (*Cfg) Float

func (c *Cfg) Float(key string) (float64, bool)

Float get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) FloatOr

func (c *Cfg) FloatOr(key string, defaultVal float64) float64

FloatOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Floats

func (c *Cfg) Floats() map[string]float64

func (*Cfg) GrabBool

func (c *Cfg) GrabBool(key string) bool

GrabBool get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) GrabFloat

func (c *Cfg) GrabFloat(key string) float64

GrabFloat get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) GrabInt

func (c *Cfg) GrabInt(key string) int

GrabInt get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) GrabMap

func (c *Cfg) GrabMap(key string) interface{}

GrabMap get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) GrabSlice

func (c *Cfg) GrabSlice(key string) interface{}

GrabSlice get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) GrabString

func (c *Cfg) GrabString(key string) string

GrabString get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) GrabStruct

func (c *Cfg) GrabStruct(key string) interface{}

GrabStruct get a configuration value according to the key, it returns zero value if no value is found.

func (*Cfg) Int

func (c *Cfg) Int(key string) (int, bool)

Int get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) IntOr

func (c *Cfg) IntOr(key string, defaultVal int) int

IntOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Ints

func (c *Cfg) Ints() map[string]int

func (*Cfg) JSON

func (c *Cfg) JSON() (string, error)

JSON returns all configs as a JSON in a string

func (*Cfg) Load

func (c *Cfg) Load(pvds ...CfgProvider) (*Cfg, error)

Load loads configuration from local path according to config's definition

func (*Cfg) Map

func (c *Cfg) Map(key string) (interface{}, bool)

Map get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) MapOr

func (c *Cfg) MapOr(key string, defaultVal interface{}) interface{}

MapOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Maps

func (c *Cfg) Maps() map[string]interface{}

func (*Cfg) Print

func (c *Cfg) Print()

Print prints all of the values in the Cfg

func (*Cfg) SetBool

func (c *Cfg) SetBool(key string, val bool)

SetBool set val in Cfg according to the key.

func (*Cfg) SetFloat

func (c *Cfg) SetFloat(key string, val float64)

SetFloat set val in Cfg according to the key.

func (*Cfg) SetInt

func (c *Cfg) SetInt(key string, val int)

SetInt set val in Cfg according to the key.

func (*Cfg) SetMap

func (c *Cfg) SetMap(key string, val interface{})

SetMap set val in Cfg according to the key.

func (*Cfg) SetSlice

func (c *Cfg) SetSlice(key string, val interface{})

SetSlice set val in Cfg according to the key.

func (*Cfg) SetString

func (c *Cfg) SetString(key string, val string)

SetString set val in Cfg according to the key.

func (*Cfg) SetStruct

func (c *Cfg) SetStruct(key string, val interface{})

SetStruct set val in Cfg according to the key.

func (*Cfg) Slice

func (c *Cfg) Slice(key string) (interface{}, bool)

Slice get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) SliceOr

func (c *Cfg) SliceOr(key string, defaultVal interface{}) interface{}

SliceOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Slices

func (c *Cfg) Slices() map[string]interface{}

func (*Cfg) String

func (c *Cfg) String(key string) (string, bool)

String get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) StringOr

func (c *Cfg) StringOr(key string, defaultVal string) string

StringOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Strings

func (c *Cfg) Strings() map[string]string

func (*Cfg) Struct

func (c *Cfg) Struct(key string) (interface{}, bool)

Struct get a configuration value according to key, the second returned value is false if nothing not found.

func (*Cfg) StructOr

func (c *Cfg) StructOr(key string, defaultVal interface{}) interface{}

StructOr get a configuration value according to the key, or it returns the defaultVal instead.

func (*Cfg) Structs

func (c *Cfg) Structs() map[string]interface{}

func (*Cfg) Template

func (c *Cfg) Template() interface{}

Template returns all configs as an interface{}

func (*Cfg) ToString

func (c *Cfg) ToString() string

String returns all of the values in the Cfg as a string

type CfgProvider

type CfgProvider interface {
	Load(dstCfg interface{}) error
}

CfgProvider is a configuration loader interface

type GoCfgCfg

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

GoCfgCfg is a configuration loader for a gocfg struct

func GoCfg

func GoCfg(srcCfg *Cfg) *GoCfgCfg

GoCfg inits a GoCfgCfg

func (*GoCfgCfg) Load

func (cfg *GoCfgCfg) Load(dstCfg interface{}) error

Load populates gocfg struct and save to

type ICfg

type ICfg interface {
	Bool(key string) (bool, bool)
	Int(key string) (int, bool)
	Float(key string) (float64, bool)
	String(key string) (string, bool)
	Map(key string) (interface{}, bool)
	Slice(key string) (interface{}, bool)
	Struct(key string) (interface{}, bool)

	BoolOr(key string, defaultVal bool) bool
	IntOr(key string, defaultVal int) int
	FloatOr(key string, defaultVal float64) float64
	StringOr(key string, defaultVal string) string
	MapOr(key string, defaultVal interface{}) interface{}
	SliceOr(key string, defaultVal interface{}) interface{}
	StructOr(key string, defaultVal interface{}) interface{}

	GrabBool(key string) bool
	GrabInt(key string) int
	GrabFloat(key string) float64
	GrabString(key string) string
	GrabMap(key string) interface{}
	GrabSlice(key string) interface{}
	GrabStruct(key string) interface{}

	Bools() map[string]bool
	Ints() map[string]int
	Floats() map[string]float64
	Strings() map[string]string
	Maps() map[string]interface{}
	Slices() map[string]interface{}
	Structs() map[string]interface{}

	SetBool(key string, val bool)
	SetInt(key string, val int)
	SetFloat(key string, val float64)
	SetString(key string, val string)
	SetStruct(key string, val interface{})

	Print()
	Debug()
	ToString() string
	JSON() (string, error)
	Template() interface{}
}

ICfg is an interface defined for consumer according to *gocfg.Cfg

type JSONCfg

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

JSONCfg is a configuration loader for a local json file

func JSON

func JSON(path string) *JSONCfg

JSON inits a JSONCfg according to the json file in the path

func (*JSONCfg) Load

func (cfg *JSONCfg) Load(dstCfg interface{}) error

Load populates json file according to the definition of the dstCfg

type JSONStrCfg

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

JSONStrCfg is a configuration loader for a json string

func JSONStr

func JSONStr(content string) *JSONStrCfg

JSONStr inits a JSONStrCfg according to the content

func (*JSONStrCfg) Load

func (cfg *JSONStrCfg) Load(dstCfg interface{}) error

Load populates content according to the definition of the dstCfg

type YAMLCfg

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

YAMLCfg is a configuration loader for a local yaml file

func YAML

func YAML(path string) *YAMLCfg

YAML inits a YAMLCfg according to the json file in the path

func (*YAMLCfg) Load

func (cfg *YAMLCfg) Load(dstCfg interface{}) error

Load populates yaml file according to the definition of the dstCfg

type YAMLStrCfg

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

YAMLStrCfg is a configuration loader for a local yaml file

func YAMLStr

func YAMLStr(content string) *YAMLStrCfg

YAMLStr inits a YAMLStrCfg according to the json file in the path

func (*YAMLStrCfg) Load

func (cfg *YAMLStrCfg) Load(dstCfg interface{}) error

Load populates yaml file according to the definition of the dstCfg

Jump to

Keyboard shortcuts

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