toml

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

func ParseFile

func ParseFile(fileName string) (*ast.Table, error)

func WriteTo

func WriteTo(t *ast.Table, w io.Writer) error

Types

type Helper

type Helper struct {
	// contains filtered or unexported fields
}

Helper is helper for simple manipulate with parsed toml data

func NewTomlHelper

func NewTomlHelper(t *ast.Table) *Helper

NewTomlHelper return new helper using *ast.Table created in toml library Parse method

func (*Helper) AddParam

func (d *Helper) AddParam(name, sectionName string, value interface{}) error

AddParam add param in section with set value

func (*Helper) AddSection

func (d *Helper) AddSection(name, after string) error

AddSection add section with name 'name' in toml data after section 'after'

func (*Helper) DeleteParam

func (d *Helper) DeleteParam(name, sectionName string) error

DeleteParam remove param from section

func (*Helper) DeleteSection

func (d *Helper) DeleteSection(name string) error

DeleteSection remove section named 'name' with subdata from toml data

func (*Helper) FindSection

func (d *Helper) FindSection(name string) (*ast.Table, error)

FindSection return *ast.Table data for section or (nil, ErrorSectionNotExists) if section not exists

func (*Helper) GetParamBool

func (d *Helper) GetParamBool(name, sectionName string) (bool, error)

GetParamBool get value for bool param

func (*Helper) GetParamFloat

func (d *Helper) GetParamFloat(name, sectionName string) (float64, error)

GetParamFloat get value for float param

func (*Helper) GetParamInt

func (d *Helper) GetParamInt(name, sectionName string) (int64, error)

GetParamInt get value for int param

func (*Helper) GetParamString

func (d *Helper) GetParamString(name, sectionName string) (string, error)

GetParamString get value for string param

func (*Helper) GetParamTime

func (d *Helper) GetParamTime(name, sectionName string) (time.Time, error)

GetParamTime get value for Time param

func (*Helper) GetTable

func (d *Helper) GetTable() *ast.Table

GetTable return *ast.Table data

func (*Helper) RenameParam

func (d *Helper) RenameParam(name, sectionName, newName string) error

RenameParam rename param

func (*Helper) RenameSection

func (d *Helper) RenameSection(name, newName string) error

RenameSection change name for section

func (*Helper) SetParam

func (d *Helper) SetParam(name, sectionName string, value interface{}) error

SetParam set value for exists param

type IDStore

type IDStore struct {
	// contains filtered or unexported fields
}

IDStore is implementation for migration id storage in toml file value

func NewIDStore

func NewIDStore(d *Helper, idChain []string) *IDStore

NewIDStore return new toml.IDStore

func (*IDStore) GetID

func (p *IDStore) GetID() string

GetID return current saved migration ID from toml data

func (*IDStore) SetID

func (p *IDStore) SetID(id string)

SetID save migration ID in toml data

Jump to

Keyboard shortcuts

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