Documentation
¶
Overview ¶
Package properties is used to read or write or modify the properties document.
Index ¶
- func Save(doc *PropertiesDocument, writer io.Writer) error
- type PropertiesDocument
- func (p PropertiesDocument) Accept(f func(typo byte, value string, key string) bool)
- func (p PropertiesDocument) Bool(key string) bool
- func (p PropertiesDocument) BoolDefault(key string, def bool) bool
- func (p *PropertiesDocument) Comment(key string, comments string) bool
- func (p *PropertiesDocument) Del(key string) bool
- func (p PropertiesDocument) Float(key string) float64
- func (p PropertiesDocument) FloatDefault(key string, def float64) float64
- func (p PropertiesDocument) Foreach(f func(value string, key string) bool)
- func (p PropertiesDocument) Get(key string) (value string, exist bool)
- func (p PropertiesDocument) Int(key string) int64
- func (p PropertiesDocument) IntDefault(key string, def int64) int64
- func (p PropertiesDocument) Object(key string, f func(k string, v string) (interface{}, error)) interface{}
- func (p PropertiesDocument) ObjectDefault(key string, def interface{}, f func(k string, v string) (interface{}, error)) interface{}
- func (p *PropertiesDocument) Set(key string, value string)
- func (p PropertiesDocument) String(key string) string
- func (p PropertiesDocument) StringDefault(key string, def string) string
- func (p PropertiesDocument) Uint(key string) uint64
- func (p PropertiesDocument) UintDefault(key string, def uint64) uint64
- func (p *PropertiesDocument) Uncomment(key string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PropertiesDocument ¶
type PropertiesDocument struct {
// contains filtered or unexported fields
}
PropertiesDocument The properties document in memory.
func Load ¶
func Load(reader io.Reader) (doc *PropertiesDocument, err error)
Load is used to create the properties document from a file or a stream.
func New ¶
func New() *PropertiesDocument
New is used to create a new and empty properties document.
It's used to generate a new document.
func (PropertiesDocument) Accept ¶
func (p PropertiesDocument) Accept(f func(typo byte, value string, key string) bool)
Accept Traverse every element of the document, include comment.
The typo parameter special the element type. If typo is '#' or '!' means current element is a comment. If typo is ' ' means current element is a empty or a space line. If typo is '=' or ':' means current element is a key-value pair. The traverse will be terminated if f return false.
func (PropertiesDocument) Bool ¶
func (p PropertiesDocument) Bool(key string) bool
Bool is same as BoolDefault but the def is false.
func (PropertiesDocument) BoolDefault ¶
func (p PropertiesDocument) BoolDefault(key string, def bool) bool
BoolDefault Retrive the bool value by key. If the element is not exist, the def will be returned. This function mapping "1", "t", "T", "true", "TRUE", "True" as true. This function mapping "0", "f", "F", "false", "FALSE", "False" as false. If the element is not exist of can not map to value of bool,the def will be returned.
func (*PropertiesDocument) Comment ¶
func (p *PropertiesDocument) Comment(key string, comments string) bool
Comment Append comments for the special item.
Return false if the special item is not exist.
func (*PropertiesDocument) Del ¶
func (p *PropertiesDocument) Del(key string) bool
Del Delete the exist item.
If the item is not exist, return false.
func (PropertiesDocument) Float ¶
func (p PropertiesDocument) Float(key string) float64
Float is same as FloatDefault but the def is 0.0 .
func (PropertiesDocument) FloatDefault ¶
func (p PropertiesDocument) FloatDefault(key string, def float64) float64
FloatDefault Retrive the float64 value by key. If the element is not exist, the def will be returned.
func (PropertiesDocument) Foreach ¶
func (p PropertiesDocument) Foreach(f func(value string, key string) bool)
Foreach Traverse all of the key-value pairs in the document. The traverse will be terminated if f return false.
func (PropertiesDocument) Get ¶
func (p PropertiesDocument) Get(key string) (value string, exist bool)
Get Retrive the value from PropertiesDocument.
If the item is not exist, the exist is false.
func (PropertiesDocument) Int ¶
func (p PropertiesDocument) Int(key string) int64
Int is ame as IntDefault but the def is 0 .
func (PropertiesDocument) IntDefault ¶
func (p PropertiesDocument) IntDefault(key string, def int64) int64
IntDefault Retrive the int64 value by key. If the element is not exist, the def will be returned.
func (PropertiesDocument) Object ¶
func (p PropertiesDocument) Object(key string, f func(k string, v string) (interface{}, error)) interface{}
Object is same as ObjectDefault but the def is nil.
Notice: If the return value can not be assign to nil, this function will panic/
func (PropertiesDocument) ObjectDefault ¶
func (p PropertiesDocument) ObjectDefault(key string, def interface{}, f func(k string, v string) (interface{}, error)) interface{}
ObjectDefault Map the value of the key to any object. The f is the customized mapping function. Return def if the element is not exist of f have a error returned.
func (*PropertiesDocument) Set ¶
func (p *PropertiesDocument) Set(key string, value string)
Set Update the value of the item of the key.
Create a new item if the item of the key is not exist.
func (PropertiesDocument) String ¶
func (p PropertiesDocument) String(key string) string
String Same as StringDefault but the def is "".
func (PropertiesDocument) StringDefault ¶
func (p PropertiesDocument) StringDefault(key string, def string) string
StringDefault Retrive the string value by key. If the element is not exist, the def will be returned.
func (PropertiesDocument) Uint ¶
func (p PropertiesDocument) Uint(key string) uint64
Uint Same as UintDefault but the def is 0 .
func (PropertiesDocument) UintDefault ¶
func (p PropertiesDocument) UintDefault(key string, def uint64) uint64
UintDefault Same as IntDefault, but the return type is uint64.
func (*PropertiesDocument) Uncomment ¶
func (p *PropertiesDocument) Uncomment(key string) bool
Uncomment Remove all of the comments for the special item.
Return false if the special item is not exist.