Documentation ¶
Overview ¶
Package properties is used to read or write or modify the properties document.
Index ¶
- func Diff(l, r *Doc, f func(DiffEvent))
- type ChangeType
- type DiffEvent
- type Doc
- func (p Doc) Accept(f func(typo byte, value, key string) bool)
- func (p Doc) Bool(key string) bool
- func (p Doc) BoolOr(key string, def bool) bool
- func (p *Doc) Comment(key, comments string) bool
- func (p *Doc) Del(key string) bool
- func (p Doc) Export() (string, error)
- func (p Doc) ExportFile(file string) error
- func (p Doc) Float64(key string) float64
- func (p Doc) Float64Or(key string, def float64) float64
- func (p Doc) Foreach(f func(value, key string) bool)
- func (p Doc) Get(key string) (value string, exist bool)
- func (p Doc) Int(key string) int
- func (p Doc) Int64(key string) int64
- func (p Doc) Int64Or(key string, def int64) int64
- func (p Doc) IntOr(key string, def int) int
- func (p Doc) Map() map[string]string
- func (p Doc) MustGet(key string) (value string)
- func (p Doc) Object(key string, f func(k, v string) (interface{}, error)) interface{}
- func (p Doc) ObjectOr(key string, def interface{}, f func(k, v string) (interface{}, error)) interface{}
- func (p Doc) Populate(b interface{}, tag string) error
- func (p Doc) Save(writer io.Writer) error
- func (p *Doc) Set(key, value string)
- func (p Doc) Str(key string) string
- func (p Doc) StrOr(key, def string) string
- func (p Doc) String() string
- func (p Doc) Uint64(key string) uint64
- func (p Doc) Uint64Or(key string, def uint64) uint64
- func (p *Doc) Uncomment(key string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ChangeType ¶
type ChangeType int
ChangeType defines the type of chaging.
const ( // Modified ... Modified ChangeType = iota // Added ... Added // Removed ... Removed // Same ... Same )
type DiffEvent ¶
type DiffEvent struct { ChangeType ChangeType Key string LeftValue string RightValue string }
DiffEvent defines ChangeEvent for properties diff
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc The properties document in memory.
func LoadMap ¶
LoadMap creates a new Properties struct from a string map. copy from https://github.com/magiconair/properties
func LoadString ¶
LoadString creates the properties document from a string.
func New ¶
func New() *Doc
New creates a new and empty properties document.
It's used to generate a new document.
func (Doc) Accept ¶
Accept traverses every line of the document, include comment.
The typo parameter special the line type. If typo is '#' or '!' means current line is a comment. If typo is ' ' means current line is a empty or a space line. If typo is '=' or ':' means current line is a key-value pair. The traverse will be terminated if f return false.
func (Doc) BoolOr ¶
BoolOr retrieve the bool value by key. If the line 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 line is not exist of can not map to value of bool,the def will be returned.
func (*Doc) Comment ¶
Comment appends comments for the special line.
Return false if the special line is not exist.
func (Doc) ExportFile ¶
ExportFile saves the doc to file.
func (Doc) Float64Or ¶
Float64Or retrieve the float64 value by key. If the line is not exist, the def will be returned.
func (Doc) Foreach ¶
Foreach traverses all of the key-value pairs in the document. The traverse will be terminated if f return false.
func (Doc) Int64Or ¶
Int64Or retrieves the int64 value by key. If the line is not exist, the def will be returned.
func (Doc) IntOr ¶
IntOr retrieves the int value by key. If the line is not exist, the def will be returned.
func (Doc) MustGet ¶
MustGet returns the expanded value for the given key if exists or panics otherwise.
func (Doc) Object ¶
Object is same as ObjectOr but the def is nil.
Notice: If the return value can not be assign to nil, this function will panic/
func (Doc) ObjectOr ¶
func (p Doc) ObjectOr(key string, def interface{}, f func(k, v string) (interface{}, error)) interface{}
ObjectOr maps the value of the key to any object. The f is the customized mapping function. Return def if the line is not exist of f have a error returned.
func (*Doc) Set ¶
Set updates the value of the line of the key.
Create a new line if the line of the key is not exist.
func (Doc) StrOr ¶
StrOr retrieves the string value by key. If the line is not exist, the def will be returned.