Documentation ¶
Overview ¶
A configuration package using Loose JSON (https://github.com/daviddengcn/ljson) as the format.
Main features include:
1) Loose JSON as the format
2) Commenting
3) Dot-seperated key
4) Include
A typical conf file:
{ // http settings http: { addr: "www.example.com" ports: [80, 8080] } #include#: "others.conf" }
Visit the project page for more details: https://github.com/daviddengcn/go-ljson-conf
Index ¶
- Constants
- func Watch(curConf *Conf, interval time.Duration, ch chan *Conf) error
- type Conf
- func (c *Conf) Bool(key string, def bool) bool
- func (c *Conf) ConfPath() villa.Path
- func (c *Conf) Decode(key string, val interface{}) error
- func (c *Conf) Duration(key string, def time.Duration) time.Duration
- func (c *Conf) Float(key string, def float64) float64
- func (c *Conf) Int(key string, def int) int
- func (c *Conf) IntList(key string, def []int) []int
- func (c *Conf) Interface(key string, def interface{}) interface{}
- func (c *Conf) List(key string, def []interface{}) []interface{}
- func (c *Conf) Object(key string, def map[string]interface{}) map[string]interface{}
- func (c *Conf) Path(key string, def villa.Path) villa.Path
- func (c *Conf) Section(key string) (conf *Conf, err error)
- func (c *Conf) String(key, def string) string
- func (c *Conf) StringList(key string, def []string) []string
- func (c *Conf) Time(key, layout string, def time.Time) time.Time
Constants ¶
const INCLUDE_KEY_TAG = "#include#"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conf ¶
type Conf struct {
// contains filtered or unexported fields
}
func Load ¶
Load reads configurations from a speicified file. If some error found during reading, it will be return, but the conf is still available. If the given path is not absolute, Load tries to find the configure file in the following order: 1. Current directory 2. Same folder the executable, and 3. User's home folder.
func (*Conf) Bool ¶
Bool retrieves a value as a bool of the key. def is returned if the value does not exist or is not a bool. A string will be converted using strconv.ParseBool.
func (*Conf) Duration ¶
Duration retrieves a value as a time.Duration. See comments of time.ParseDuration for supported formats.
func (*Conf) Float ¶
Float retrieves a value as a float64 of the key. def is returned if the value does not exist or is not a number. A string will be converted using strconv.ParseFloat.
func (*Conf) Int ¶
Int retrieves a value as a string of the key. def is returned if the value does not exist or is not a number. A float number will be round up to the closest interger. A string will be converted using strconv.ParseInt.
func (*Conf) IntList ¶
IntList retrieves a value as a slice of int of the key. def is returned if the value does not exist or is not an array. Elements of the array are converted to int. Zero is used when converting failed.
func (*Conf) Interface ¶
Interface retrieves a value as an interface{} of the key. def is returned if the value does not exist.
func (*Conf) List ¶
List retrieves a value as a slice of interface{} of the key. def is returned if the value does not exist or is not an array.
func (*Conf) Object ¶
Object retrieves a value as a map[string]interface{} of the key. def is returned if the value does not exist or is not an object.
func (*Conf) String ¶
String retrieves a value as a string of the key. def is returned if the value does not exist or cannot be converted to a string(e.g. is an object).
func (*Conf) StringList ¶
StringList retrieves a value as a slice of string of the key. def is returned if the value does not exist or is not an array. Elements of the array are converted to strings using fmt.Sprint.