config

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

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

Go to latest
Published: Aug 31, 2016 License: MIT Imports: 6 Imported by: 4

README

Config Readme


This package is used to get config params in json format text file.


ReadCfg

func ReadCfg(fn string)

read and parse config file, if there has any error, it will panic.

Get

func Get(key string) interface{}

Get config param by key, if key does not exists, it return nil.

GetMust

func GetMust(key string) interface{}

Just like Get, but if the key does not exist, it will panic.

GetString, GetStringDefault, GetStringMust

func GetString(key string) string
func GetStringMust(key string) string
func GetStringDefault(key, def string) string

Get config param by key, return a string. if the key does not exist, GetString return "", GetStringMust will panic, and GetStringDefault will return def.

GetInt, GetInt64Default, GetIntDefault, GetFloat,

func GetInt(key string) (int64, bool)
func GetInt64Default(key string, dv int64) int64
func GetIntDefault(key string, dv int) int
func GetFloat(key string) (float64, bool)

Just like GetString, but return int or float

GetBoolean, GetBooleanDefault

func GetBoolean(key string) (bool, bool)
func GetBooleanDefault(key string, dv bool) bool

Just like GetString, but return bool

Scan

func Scan(key string, dest interface{}) (err error) 

Scan can convert to any type, dest MUST be a pointer.

Use it like this:

var var1 []int

Scan("key1", &var1)

more examples is in config_test.go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	KeyNotExist = errors.New("key not exist")
)

Functions

func Get

func Get(key string) interface{}

Get if the key do not exist, return nil

func GetBoolean

func GetBoolean(key string) (bool, bool)

func GetBooleanDefault

func GetBooleanDefault(key string, dv bool) bool

func GetBytes

func GetBytes(key string) ([]byte, bool)

func GetBytesDefault

func GetBytesDefault(key string, dv []byte) []byte

func GetFloat

func GetFloat(key string) (float64, bool)

func GetInt

func GetInt(key string) (int64, bool)

GetInt

func GetInt64Default

func GetInt64Default(key string, dv int64) int64

func GetIntDefault

func GetIntDefault(key string, dv int) int

func GetMust

func GetMust(key string) interface{}

GetMust if the key do not exist, panic

func GetString

func GetString(key string) string

GetString Get string type by key

func GetStringDefault

func GetStringDefault(key, def string) string

GetString Get string type by key, if key not exist, return the default

func GetStringMust

func GetStringMust(key string) string

GetString Get string type by key, if not exist, panic

func ReadCfg

func ReadCfg(fn string) error

read config file

func Scan

func Scan(key string, dest interface{}) (err error)

Scan

Types

type Config

type Config map[string]interface{}

func ReadConfigFile

func ReadConfigFile(fn string) (Config, error)

read config file, return Config

func (Config) ScanConfig

func (c Config) ScanConfig(key string, dest interface{}) error

ScanConfig

Jump to

Keyboard shortcuts

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