pbconfig

package
v0.0.0-...-6bcf8dd Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const INT_SIZE int = int(unsafe.Sizeof(0))

Variables

This section is empty.

Functions

func Expand

func Expand(path string) (string, error)

Expand expands the path to include the home directory if the path is prefixed with `~`. If it isn't prefixed with `~`, the path is returned as-is.

func ExpandValueEnv

func ExpandValueEnv(s string) string

ExpandValueEnv returns value of convert with environment variable. Return default value if environment variable is empty or not exist. Must begin with $.

It accept value formats "$env" , "${env}" , "${env||defaultValue}". Examples:

v1 := config.ExpandValueEnv("$the result: $GOPATH")			// return the GOPATH environment variable.
v2 := config.ExpandValueEnv("$the result: ${GOPATH}")			// return the GOPATH environment variable.
v3 := config.ExpandValueEnv("$the result: ${GOPATHX||/usr/local/go}")	// return the default value "/usr/local/go/".

func ExpandValueEnvForMap

func ExpandValueEnvForMap(m map[string]interface{}) map[string]interface{}

ExpandValueEnvForMap convert all string value with environment variable.

func HomeDir

func HomeDir() (string, error)

Dir returns the home directory for the executing user. An error is returned if a home directory cannot be detected.

func IsBigEndian

func IsBigEndian() bool

system byte order

func Register

func Register(name string, adapter Config)

Register

Types

type Config

type Config interface {
	Load(file string) (Configor, error)
	ParseData(data []byte) (Configor, error)
}

type Configor

type Configor interface {
	SetString(key, val string) error

	GetString(key string, defaultVal ...string) string
	GetInt(key string, defaultVal ...int) (int, error)
	GetInt64(key string, defaultVal ...int64) (int64, error)
	GetBool(key string) (bool, error)
	GetFloat(key string, defaultVal ...float64) (float64, error)

	GetRawValue(key string) (interface{}, error)
	SaveFile(file string) error
}

func NewConfig

func NewConfig(adapterName, filename string) (Configor, error)

NewConfig adapterName is json/yaml. filename is the config file path.

func NewConfigData

func NewConfigData(adapterName string, data []byte) (Configor, error)

NewConfigData adapterName is json/yaml. data is the config data.

type JSONConfig

type JSONConfig struct {
}

func (*JSONConfig) Load

func (jsc *JSONConfig) Load(file string) (Configor, error)

func (*JSONConfig) ParseData

func (jsc *JSONConfig) ParseData(data []byte) (Configor, error)

type JSONObject

type JSONObject struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*JSONObject) GetBool

func (jo *JSONObject) GetBool(key string) (bool, error)

func (*JSONObject) GetFloat

func (jo *JSONObject) GetFloat(key string, defaultVal ...float64) (float64, error)

func (*JSONObject) GetInt

func (jo *JSONObject) GetInt(key string, defaultVal ...int) (int, error)

func (*JSONObject) GetInt64

func (jo *JSONObject) GetInt64(key string, defaultVal ...int64) (int64, error)

func (*JSONObject) GetRawValue

func (jo *JSONObject) GetRawValue(key string) (interface{}, error)

func (*JSONObject) GetString

func (jo *JSONObject) GetString(key string, defaultVal ...string) string

func (*JSONObject) SaveFile

func (jo *JSONObject) SaveFile(file string) error

func (*JSONObject) SetString

func (jo *JSONObject) SetString(key, val string) error

type YAMLConfig

type YAMLConfig struct {
}

func (*YAMLConfig) Load

func (yc *YAMLConfig) Load(file string) (Configor, error)

func (*YAMLConfig) ParseData

func (yc *YAMLConfig) ParseData(data []byte) (Configor, error)

type YAMLObject

type YAMLObject struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*YAMLObject) GetBool

func (yo *YAMLObject) GetBool(key string) (bool, error)

func (*YAMLObject) GetFloat

func (yo *YAMLObject) GetFloat(key string, defaultVal ...float64) (float64, error)

func (*YAMLObject) GetInt

func (yo *YAMLObject) GetInt(key string, defaultVal ...int) (int, error)

func (*YAMLObject) GetInt64

func (yo *YAMLObject) GetInt64(key string, defaultVal ...int64) (int64, error)

func (*YAMLObject) GetRawValue

func (yo *YAMLObject) GetRawValue(key string) (interface{}, error)

func (*YAMLObject) GetString

func (yo *YAMLObject) GetString(key string, defaultVal ...string) string

func (*YAMLObject) SaveFile

func (yo *YAMLObject) SaveFile(file string) error

func (*YAMLObject) SetString

func (yo *YAMLObject) SetString(key, val string) error

Jump to

Keyboard shortcuts

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