Documentation ¶
Index ¶
- Variables
- func ParseFile(fileName string) (*ast.Table, error)
- func WriteTo(t *ast.Table, w io.Writer) error
- type Helper
- func (d *Helper) AddParam(name, sectionName string, value interface{}) error
- func (d *Helper) AddSection(name, after string) error
- func (d *Helper) DeleteParam(name, sectionName string) error
- func (d *Helper) DeleteSection(name string) error
- func (d *Helper) FindSection(name string) (*ast.Table, error)
- func (d *Helper) GetParamBool(name, sectionName string) (bool, error)
- func (d *Helper) GetParamFloat(name, sectionName string) (float64, error)
- func (d *Helper) GetParamInt(name, sectionName string) (int64, error)
- func (d *Helper) GetParamString(name, sectionName string) (string, error)
- func (d *Helper) GetParamTime(name, sectionName string) (time.Time, error)
- func (d *Helper) GetTable() *ast.Table
- func (d *Helper) RenameParam(name, sectionName, newName string) error
- func (d *Helper) RenameSection(name, newName string) error
- func (d *Helper) SetParam(name, sectionName string, value interface{}) error
- type IDStore
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorParamNotExists error for not exists params when read ErrorParamNotExists = errors.New("param not exists") // ErrorParamAlreadyExists error for already exists params when add ErrorParamAlreadyExists = errors.New("param already exists") // ErrorSectionNotExists error for not exists section when search ErrorSectionNotExists = errors.New("section not exists") // ErrorSectionAlreadyExists error for already exists section when add ErrorSectionAlreadyExists = errors.New("section already exists") )
var Settings = toml.Config{ NormFieldName: func(rt reflect.Type, key string) string { return key }, FieldToKey: func(rt reflect.Type, field string) string { return field }, MissingField: func(rt reflect.Type, field string) error { link := "" if unicode.IsUpper(rune(rt.Name()[0])) && rt.PkgPath() != "main" { link = fmt.Sprintf(", see https://godoc.org/%s#%s for available fields", rt.PkgPath(), rt.Name()) } return fmt.Errorf("field '%s' is not defined in %s%s", field, rt.String(), link) }, }
Settings ensure that TOML keys use the same names as Go struct fields.
Functions ¶
Types ¶
type Helper ¶
type Helper struct {
// contains filtered or unexported fields
}
Helper is helper for simple manipulate with parsed toml data
func NewTomlHelper ¶
NewTomlHelper return new helper using *ast.Table created in toml library Parse method
func (*Helper) AddSection ¶
AddSection add section with name 'name' in toml data after section 'after'
func (*Helper) DeleteParam ¶
DeleteParam remove param from section
func (*Helper) DeleteSection ¶
DeleteSection remove section named 'name' with subdata from toml data
func (*Helper) FindSection ¶
FindSection return *ast.Table data for section or (nil, ErrorSectionNotExists) if section not exists
func (*Helper) GetParamBool ¶
GetParamBool get value for bool param
func (*Helper) GetParamFloat ¶
GetParamFloat get value for float param
func (*Helper) GetParamInt ¶
GetParamInt get value for int param
func (*Helper) GetParamString ¶
GetParamString get value for string param
func (*Helper) GetParamTime ¶
GetParamTime get value for Time param
func (*Helper) RenameParam ¶
RenameParam rename param
func (*Helper) RenameSection ¶
RenameSection change name for section