var ErrInvalidNumArgs = fmt.Errorf("invalid number of arguments")
var ErrInvalidSection = fmt.Errorf("syntactically invalid section")
func EscapeIniValue(val string) string
func IniParse(sink IniSink, filename string) error
Open, read, and parse an INI file. If the file is incorrectly formatted, will return an error of type ParseErrors.
func IniParseContents(sink IniSink, filename string, contents []byte) error
Parse the contents of an INI file. The filename argument is used only for error messages.
▹ Example
func IniQKey(s *IniSection, key string) string
Produce a fully "qualified" key consisting of the section, optional subsection, and key separated by dots, as understood by the git-config command.
func ValidIniKey(s string) bool
Test if string is a valid INI file key. Valid keys start with a letter followed by zero or more alphanumeric characters or '-' characters.
func ValidIniSection(s string) bool
Test if a string is a valid INI file section name. Section names cannot be the empty string and must consist only of alphanumeric characters and '-'.
func ValidIniSubsection(s string) bool
Test if a string is a valid subsection name in an INI file. Specifically, subsection names may not contain a newline or NUL byte.
Error that an IniSink's Value method should return when there is a problem with the key, rather than a problem with the value. By default, the line and column number of an error will correspond to the start of the value, but with BadKey the error will point to the key.
type BadKey string
func (err BadKey) Error() string
Just a random error type useful for bad values in INI files. Exists for symmetry with BadKey, though BadValue is in no way special.
type BadValue string
func (err BadValue) Error() string
A generic IniSink that uses fmt.Sscan to parse non-string fields.
type GenericIniSink struct { // If non-nil, only match this specific section (otherwise // ignore). Sec *IniSection // Pointers to the fields that should be parsed. Fields map[string]interface{} }
▹ Example
func NewGenericSink(args ...string) *GenericIniSink
NewGenericSink([section [, subsection])
func (s *GenericIniSink) AddField(name string, ptr interface{})
Add a field to be parsed
func (s *GenericIniSink) AddStruct(i interface{})
Populate a GenericIniSink with fields of a struct, using the field name or or the ini struct field tag (`ini:"field-name"`) if one exists. Tag `ini:"-"` says to ignore a field. Note that i must be a pointer to a structure or this function will panic.
func (s *GenericIniSink) IniSink() IniSink
func (s *GenericIniSink) Item(ii IniItem) error
func (s *GenericIniSink) SaveAll(ies *IniEdits, includeZero bool)
Save the current state of an Ini-parsable structure to a set of IniEdits. This is useful for creating an initial file. If includeZero is true, then all fields are saved; otherwise, only ones with non-default values are saved.
func (s *GenericIniSink) String() string
You can parse an INI file into an IniEditor, Set, Del, or Add key-value pairs, then write out the result using WriteTo. Preserves most comments and file ordering.
type IniEditor struct {
// contains filtered or unexported fields
}
func NewIniEdit(filename string, contents []byte) (*IniEditor, error)
Create an IniEdit for a file with contents. Note that filename is only used for parse errors; the file must already be read before calling this function.
func (ie *IniEditor) Add(is *IniSection, key, value string)
Add a new instance of key to the file without deleting any previous instance of the key.
func (ie *IniEditor) Del(is *IniSection, key string)
Delete all instances of a key from the file.
func (ie *IniEditor) Done(r IniRange)
Called by IniParseContents; do not call directly.
func (ie *IniEditor) Item(ii IniItem) error
Called by IniParseContents; do not call directly.
func (ie *IniEditor) Section(ss IniSecStart) error
Called by IniParseContents; do not call directly.
func (ie *IniEditor) Set(is *IniSection, key, value string)
Replace all instances of key with a single one equal to value.
func (ie *IniEditor) String() string
func (ie *IniEditor) WriteTo(w io.Writer) (int64, error)
Write the contents of IniEditor to a Writer after applying edits have been made.
A bunch of edits to be applied to an INI file.
type IniEdits []func(*IniEditor)
func (ie *IniEdits) Add(sec string, args ...string) error
Add a key, value pair. Invoke as Add(sec, subsec, key, value) or Add(sec, key, value).
func (ie *IniEdits) Apply(target *IniEditor)
Apply edits.
func (ie *IniEdits) Del(sec string, args ...string) error
Delete a key. Invoke as Del(sec, subsec, key) or Del(sec, key).
func (ie *IniEdits) Set(sec string, args ...string) error
Add a key, value pair. Invoke as Set(sec, subsec, key, value) or Set(sec, key, value).
type IniItem struct { *IniSection Key string Value *string IniRange }
func (ii *IniItem) QKey() string
Returns the Key qualified by the section (see IniQKey).
func (ii *IniItem) Val() string
Returns Value or an empty string if Value is nil.
type IniRange struct { // The text of a key, value pair or section header lies between // StartIndex and EndIndex. If PrevEndIndex != StartIndex, then // the bytes between PrevEndIndex and StartIndex constitute a // comment or blank lines. StartIndex, EndIndex, PrevEndIndex int // The entire input file Input []byte }
type IniSecStart struct { IniSection IniRange }
Section of an INI file. A nil *IniSection corresponds to the "section-free" part of the file before the first section, which the git-config man page says is not valid, but the git-config tool halfway supports.
type IniSection struct { Section string Subsection *string }
func (s *IniSection) Eq(s2 *IniSection) bool
True if two *IniSection have the same contents.
func (s *IniSection) String() string
Renders as [section] or [section "subsection"]. The nil *IniSection renders as an empty string. Panics if the subsection includes the illegal characters '\n' or '\000'.
func (s *IniSection) Valid() bool
Returns false if either the section or subsection is illegal. Returns true for a nil *IniSection.
Type that receives and processes the parsed INI file. Note that if there is also Section(IniSecStart)error method, this is called at the start of sections, and if there is a Done(IniRange) method it is called at the end of the file.
type IniSink interface { // optional: // Section(IniSecStart) error // Init() // Done() // Item(IniItem) error }
type IniSinker interface { IniSink() IniSink }
type IniSinks []IniSink
func (s IniSinks) Done(IniRange)
func (s IniSinks) IniSink() IniSink
func (s IniSinks) Init()
func (s IniSinks) Item(ii IniItem) error
func (s *IniSinks) Push(i IniSink)
func (s IniSinks) Section(ss IniSecStart) error
func (s IniSinks) String() string
A single parse error in an IniFile.
type ParseError struct { File string Lineno, Colno int Msg string }
func (err ParseError) Error() string
The collection of parse errors that resulted from parsing a file.
type ParseErrors []ParseError
func (err ParseErrors) Error() string