xcfg

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrError        = errors.New("")
	ErrLoadFailed   = fmt.Errorf("%wloading failed", ErrError)
	ErrSaveFailed   = fmt.Errorf("%wsaving failed", ErrError)
	ErrFileNotExist = fmt.Errorf("%wfile does not exist", ErrError)
	ErrEncodeFailed = fmt.Errorf("%wencoding failed", ErrError)
	ErrDecodeFailed = fmt.Errorf("%wdecoding failed", ErrError)
)

Functions

This section is empty.

Types

type BaseFileConfig

type BaseFileConfig struct {
	Dict

	// secure data encoding and decoding callback
	Encode func([]byte) ([]byte, error)
	Decode func([]byte) ([]byte, error)
	// contains filtered or unexported fields
}

base configuration file handler

func NewBaseFileConfig

func NewBaseFileConfig(filePath string, defaults Dict) *BaseFileConfig

func (*BaseFileConfig) Buffer

func (fc *BaseFileConfig) Buffer() Dict

return handler to internal Dict object

func (*BaseFileConfig) Dump

func (fc *BaseFileConfig) Dump() ([]byte, error)

return the contents of the config file

func (*BaseFileConfig) GetSecure

func (fc *BaseFileConfig) GetSecure(key string, defval any) (any, error)

get secure value from config by key

func (*BaseFileConfig) Purge

func (fc *BaseFileConfig) Purge() error

func (*BaseFileConfig) SetSecure

func (fc *BaseFileConfig) SetSecure(key string, newval any) error

set secure value in config by key, creates key if not exist

type BlobConfig

type BlobConfig struct {
	*BaseFileConfig
}

binary configuration file handler

func NewBlobConfig

func NewBlobConfig(filePath string, defaults Dict) *BlobConfig

func (*BlobConfig) Load

func (bc *BlobConfig) Load() error

load config buffer from file and merge with defaults

func (*BlobConfig) Save

func (bc *BlobConfig) Save() error

save the current config buffer to file

func (*BlobConfig) String

func (bc *BlobConfig) String() string

type Dict

type Dict map[string]any

Dict type with nested keys support

func NewDict

func NewDict(d Dict) Dict

initialize new Dict with map type conversion

func (Dict) Delete

func (d Dict) Delete(key string)

delete value from dict by key

func (Dict) Get

func (d Dict) Get(key string, defval any) any

get value from dict by key or return default value

func (Dict) KeyExist

func (d Dict) KeyExist(key string) bool

check if key exist in dict

func (Dict) Keys

func (d Dict) Keys() []string

return sorted list of all nested level keys

func (Dict) KeysN

func (d Dict) KeysN(lvl int) []string

return sorted recursive list up to N level nested keys

func (Dict) Set

func (d Dict) Set(key string, newval any)

set value in dict by key

func (Dict) Update

func (d Dict) Update(updt Dict)

update dict with updt dict

type FileConfig

type FileConfig interface {
	Load() error
	Save() error
	Purge() error
	Dump() ([]byte, error)
	Buffer() Dict
	Keys() []string
	KeysN(int) []string
	KeyExist(string) bool
	Get(string, any) any
	Set(string, any)
	Delete(string)
	GetSecure(string, any) (any, error)
	SetSecure(string, any) error
}

type JsonConfig

type JsonConfig struct {
	*BaseFileConfig
}

JSON configuration file handler

func NewJsonConfig

func NewJsonConfig(filePath string, defaults Dict) *JsonConfig

func (*JsonConfig) Load

func (jc *JsonConfig) Load() error

load config buffer from file and merge with defaults

func (*JsonConfig) Save

func (jc *JsonConfig) Save() error

save the current config buffer to file

func (*JsonConfig) String

func (jc *JsonConfig) String() string

Jump to

Keyboard shortcuts

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