import "gopkg.in/go-ini/ini.v1"
Package ini provides INI file read and write functionality in Go.
error.go file.go ini.go key.go parser.go section.go struct.go
const ( // Name for default section. You can use this constant or the string literal. // In most of cases, an empty string is all you need to access the section. DEFAULT_SECTION = "DEFAULT" )
var ( // Delimiter to determine or compose a new line. // This variable will be changed to "\r\n" automatically on Windows // at package init time. LineBreak = "\n" // Place custom spaces when PrettyFormat and PrettyEqual are both disabled DefaultFormatLeft = "" DefaultFormatRight = "" // Indicate whether to align "=" sign with spaces to produce pretty output // or reduce all possible spaces for compact format. PrettyFormat = true // Place spaces around "=" sign even when PrettyFormat is false PrettyEqual = false // Explicitly write DEFAULT section header DefaultHeader = false // Indicate whether to put a line between sections PrettySection = true )
MapTo maps data sources to given struct.
func MapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error
MapTo maps data sources to given struct with name mapper.
ReflectFrom reflects data sources from given struct.
func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error
ReflectFrom reflects data sources from given struct with name mapper.
StrictMapTo maps data sources to given struct in strict mode, which returns all possible error including value parsing error.
func StrictMapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error
StrictMapToWithMapper maps data sources to given struct with name mapper in strict mode, which returns all possible error including value parsing error.
Version returns current package version literal.
func (err ErrDelimiterNotFound) Error() string
type File struct { // Should make things safe, but sometimes doesn't matter. BlockMode bool NameMapper ValueMapper // contains filtered or unexported fields }
File represents a combination of a or more INI file(s) in memory.
Empty returns an empty file object.
InsensitiveLoad has exactly same functionality as Load function except it forces all section and key names to be lowercased.
Load loads and parses from INI data sources. Arguments can be mixed of file name with string type, or raw data in []byte. It will return error if list contains nonexistent files.
func LoadSources(opts LoadOptions, source interface{}, others ...interface{}) (_ *File, err error)
LooseLoad has exactly same functionality as Load function except it ignores nonexistent files instead of returning error.
ShadowLoad has exactly same functionality as Load function except it allows have shadow keys.
Append appends one or more data sources and reloads automatically.
ChildSections returns a list of child sections of given section name.
DeleteSection deletes a section.
GetSection returns section by given name.
MapTo maps file to given struct.
NewRawSection creates a new section with an unparseable body.
NewSection creates a new section.
NewSections creates a list of sections.
ReflectFrom reflects file from given struct.
Reload reloads and parses all data sources.
SaveTo writes content to file system.
SaveToIndent writes content to file system with given value indention.
Section assumes named section exists and returns a zero-value when not.
SectionStrings returns list of section names.
Section returns list of Section.
MapTo maps file to given struct in strict mode, which returns all possible error including value parsing error.
WriteTo writes file content into io.Writer.
WriteToIndent writes content into io.Writer with given indention. If PrettyFormat has been set to be true, it will align "=" sign with spaces under each section.
Key represents a key under a section.
AddShadow adds a new shadow key to itself.
Bool returns bool type value.
Duration returns time.Duration type value.
Float64 returns float64 type value.
Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value.
In always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InFloat64 always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InInt always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InInt64 always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InTime always parses with RFC3339 format and returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InTimeFormat always parses with given format and returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InUint always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
InUint64 always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
Int returns int type value.
Int64 returns int64 type value.
Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value.
Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value.
MustBool always returns value without error, it returns false if error occurs.
MustDuration always returns value without error, it returns zero value if error occurs.
MustFloat64 always returns value without error, it returns 0.0 if error occurs.
MustInt always returns value without error, it returns 0 if error occurs.
MustInt64 always returns value without error, it returns 0 if error occurs.
MustString returns default value if key value is empty.
MustTime always parses with RFC3339 format and returns value without error, it returns zero value if error occurs.
MustTimeFormat always parses with given format and returns value without error, it returns zero value if error occurs.
MustUint always returns value without error, it returns 0 if error occurs.
MustUint64 always returns value without error, it returns 0 if error occurs.
Name returns name of key.
NestedValues returns nested values stored in the key. It is possible returned value is nil if no nested values stored in the key.
RangeFloat64 checks if value is in given range inclusively, and returns default value if it's not.
RangeInt checks if value is in given range inclusively, and returns default value if it's not.
RangeInt64 checks if value is in given range inclusively, and returns default value if it's not.
RangeTime checks if value with RFC3339 format is in given range inclusively, and returns default value if it's not.
RangeTimeFormat checks if value with given format is in given range inclusively, and returns default value if it's not.
SetValue changes key value.
StrictFloat64s returns list of float64 divided by given delimiter or error on first invalid input.
StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input.
StrictInts returns list of int divided by given delimiter or error on first invalid input.
StrictTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter or error on first invalid input.
StrictTimesFormat parses with given format and returns list of time.Time divided by given delimiter or error on first invalid input.
StrictUint64s returns list of uint64 divided by given delimiter or error on first invalid input.
StrictUints returns list of uint divided by given delimiter or error on first invalid input.
String returns string representation of value.
Strings returns list of string divided by given delimiter.
StringsWithShadows returns list of string divided by given delimiter. Shadows will also be appended if any.
Time parses with RFC3339 format and returns time.Time type value.
TimeFormat parses with given format and returns time.Time type value.
Times parses with RFC3339 format and returns list of time.Time divided by given delimiter. Any invalid input will be treated as zero value (0001-01-01 00:00:00 +0000 UTC).
TimesFormat parses with given format and returns list of time.Time divided by given delimiter. Any invalid input will be treated as zero value (0001-01-01 00:00:00 +0000 UTC).
Uint returns uint type valued.
Uint64 returns uint64 type value.
Uint64s returns list of uint64 divided by given delimiter. Any invalid input will be treated as zero value.
Uints returns list of uint divided by given delimiter. Any invalid input will be treated as zero value.
ValidFloat64s returns list of float64 divided by given delimiter. If some value is not float, then it will not be included to result list.
ValidInt64s returns list of int64 divided by given delimiter. If some value is not 64-bit integer, then it will not be included to result list.
ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will not be included to result list.
ValidTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter.
ValidTimesFormat parses with given format and returns list of time.Time divided by given delimiter.
ValidUint64s returns list of uint64 divided by given delimiter. If some value is not 64-bit unsigned integer, then it will not be included to result list.
ValidUints returns list of uint divided by given delimiter. If some value is not unsigned integer, then it will not be included to result list.
Validate accepts a validate function which can return modifed result as key value.
Value returns raw value of key for performance purpose.
ValueWithShadows returns raw values of key and its shadows if any.
type LoadOptions struct { // Loose indicates whether the parser should ignore nonexistent files or return error. Loose bool // Insensitive indicates whether the parser forces all section and key names to lowercase. Insensitive bool // IgnoreContinuation indicates whether to ignore continuation lines while parsing. IgnoreContinuation bool // IgnoreInlineComment indicates whether to ignore comments at the end of value and treat it as part of value. IgnoreInlineComment bool // SkipUnrecognizableLines indicates whether to skip unrecognizable lines that do not conform to key/value pairs. SkipUnrecognizableLines bool // AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing. // This type of keys are mostly used in my.cnf. AllowBooleanKeys bool // AllowShadows indicates whether to keep track of keys with same name under same section. AllowShadows bool // AllowNestedValues indicates whether to allow AWS-like nested values. // Docs: http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#nested-values AllowNestedValues bool // AllowPythonMultilineValues indicates whether to allow Python-like multi-line values. // Docs: https://docs.python.org/3/library/configparser.html#supported-ini-file-structure // Relevant quote: Values can also span multiple lines, as long as they are indented deeper // than the first line of the value. AllowPythonMultilineValues bool // SpaceBeforeInlineComment indicates whether to allow comment symbols (\# and \;) inside value. // Docs: https://docs.python.org/2/library/configparser.html // Quote: Comments may appear on their own in an otherwise empty line, or may be entered in lines holding values or section names. // In the latter case, they need to be preceded by a whitespace character to be recognized as a comment. SpaceBeforeInlineComment bool // UnescapeValueDoubleQuotes indicates whether to unescape double quotes inside value to regular format // when value is surrounded by double quotes, e.g. key="a \"value\"" => key=a "value" UnescapeValueDoubleQuotes bool // UnescapeValueCommentSymbols indicates to unescape comment symbols (\# and \;) inside value to regular format // when value is NOT surrounded by any quotes. // Note: UNSTABLE, behavior might change to only unescape inside double quotes but may noy necessary at all. UnescapeValueCommentSymbols bool // UnparseableSections stores a list of blocks that are allowed with raw content which do not otherwise // conform to key/value pairs. Specify the names of those blocks here. UnparseableSections []string // KeyValueDelimiters is the sequence of delimiters that are used to separate key and value. By default, it is "=:". KeyValueDelimiters string }
NameMapper represents a ini tag name mapper.
var ( // AllCapsUnderscore converts to format ALL_CAPS_UNDERSCORE. AllCapsUnderscore NameMapper = func(raw string) string { newstr := make([]rune, 0, len(raw)) for i, chr := range raw { if isUpper := 'A' <= chr && chr <= 'Z'; isUpper { if i > 0 { newstr = append(newstr, '_') } } newstr = append(newstr, unicode.ToUpper(chr)) } return string(newstr) } // TitleUnderscore converts to format title_underscore. TitleUnderscore NameMapper = func(raw string) string { newstr := make([]rune, 0, len(raw)) for i, chr := range raw { if isUpper := 'A' <= chr && chr <= 'Z'; isUpper { if i > 0 { newstr = append(newstr, '_') } chr -= ('A' - 'a') } newstr = append(newstr, chr) } return string(newstr) } )
Built-in name getters.
Section represents a config section.
Body returns rawBody of Section if the section was marked as unparseable. It still follows the other rules of the INI format surrounding leading/trailing whitespace.
ChildSections returns a list of child sections of current section. For example, "[parent.child1]" and "[parent.child12]" are child sections of section "[parent]".
DeleteKey deletes a key from section.
GetKey returns key in section by given name.
HasKey returns true if section contains a key with given name.
HasValue returns true if section contains given raw value.
Haskey is a backwards-compatible name for HasKey. TODO: delete me in v2
Key assumes named Key exists in section and returns a zero-value when not.
KeyStrings returns list of key names of section.
Keys returns list of keys of section.
KeysHash returns keys hash consisting of names and values.
MapTo maps section to given struct.
Name returns name of Section.
NewBooleanKey creates a new boolean type key to given section.
NewKey creates a new key to given section.
ParentKeys returns list of keys of parent section.
ReflectFrom reflects secion from given struct.
SetBody updates body content only if section is raw.
MapTo maps section to given struct in strict mode, which returns all possible error including value parsing error.
ValueMapper represents a mapping function for values, e.g. os.ExpandEnv
Package ini imports 15 packages (graph) and is imported by 1 packages. Updated 2019-01-03. Refresh now. Tools for package owners.