Package-Level Type Names (total 16, in which 10 are exported)
/* sort exporteds by: | */
DebugFunc is the type of function called to log parse events.
ErrDelimiterNotFound indicates the error type of no delimiter is found which there should be one.
Linestring( T) Error() string
T : error
File represents a combination of one or more INI files in memory.
Should make things safe, but sometimes doesn't matter.
NameMapperNameMapperValueMapperValueMapperdataSources[]dataSourcelocksync.RWMutexoptionsLoadOptions
To keep track of the index of a section with same name.
This meta list is only used with non-unique section names are allowed.
To keep data in order.
Actual data is stored here.
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 or all sections with given name.
DeleteSectionWithIndex deletes a section with given name and index.
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.
SectionWithIndex assumes named section exists and returns a new section when not.
Sections returns a list of Section stored in the current instance.
SectionsByName returns all sections with given name.
StrictMapTo 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.
parse parses data through an io.Reader.
(*T) reload(s dataSource) error(*T) writeToBuffer(indent string) (*bytes.Buffer, error)
*T : io.WriterTo
func Empty(opts ...LoadOptions) *File
func InsensitiveLoad(source interface{}, others ...interface{}) (*File, error)
func Load(source interface{}, others ...interface{}) (*File, error)
func LoadSources(opts LoadOptions, source interface{}, others ...interface{}) (_ *File, err error)
func LooseLoad(source interface{}, others ...interface{}) (*File, error)
func ShadowLoad(source interface{}, others ...interface{}) (*File, error)
func newFile(dataSources []dataSource, opts LoadOptions) *File
func ReflectFrom(cfg *File, v interface{}) error
func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error
func StructReflector.ReflectINIStruct(*File) error
func newSection(f *File, name string) *Section
Key represents a key under a section.
CommentstringisAutoIncrementboolisBooleanTypeboolisShadowboolnamestringnestedValues[]strings*Sectionshadows[]*Keyvaluestring
AddNestedValue adds a nested value to the key.
AddShadow adds a new shadow key to itself.
Bool returns bool type value.
Bools returns list of bool divided by given delimiter. Any invalid input will be treated as zero 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.
StrictBools returns list of bool divided by given delimiter or error on first invalid input.
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.
ValidBools returns list of bool divided by given delimiter. If some value is not 64-bit unsigned
integer, then it will not be included to result list.
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.
(*T) addNestedValue(val string) error(*T) addShadow(val string) error
doParse transforms strings to different types
parseBools transforms strings to bools.
parseFloat64s transforms strings to float64s.
parseInt64s transforms strings to int64s.
parseInts transforms strings to ints.
parseTimesFormat transforms strings to times in given format.
parseUint64s transforms strings to uint64s.
parseUints transforms strings to uints.
transformValue takes a raw value and transforms to its final string.
*T : fmt.Stringer
*T : gopkg.in/yaml.v2.jsonNumber
*T : context.stringer
*T : os/signal.stringer
*T : runtime.stringer
func (*Section).GetKey(name string) (*Key, error)
func (*Section).Key(name string) *Key
func (*Section).Keys() []*Key
func (*Section).NewBooleanKey(name string) (*Key, error)
func (*Section).NewKey(name, val string) (*Key, error)
func (*Section).ParentKeys() []*Key
func newKey(s *Section, name, val string) *Key
func reflectSliceWithProperType(key *Key, field reflect.Value, delim string, allowShadow bool) error
func reflectWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow bool) error
func setSliceWithProperType(key *Key, field reflect.Value, delim string, allowShadow, isStrict bool) error
func setWithProperType(t reflect.Type, key *Key, field reflect.Value, delim string, allowShadow, isStrict bool) error
LoadOptions contains all customized options used for load data source(s).
AllowBooleanKeys indicates whether to allow boolean type keys or treat as value is missing.
This type of keys are mostly used in my.cnf.
AllowNestedValues indicates whether to allow AWS-like nested values.
Docs: http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#nested-values
AllowNonUniqueSections indicates whether to allow sections with the same name multiple times.
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.
AllowShadows indicates whether to keep track of keys with same name under same section.
ChildSectionDelimiter is the delimiter that is used to separate child sections. By default, it is ".".
DebugFunc is called to collect debug information (currently only useful to debug parsing Python-style multiline values).
IgnoreContinuation indicates whether to ignore continuation lines while parsing.
IgnoreInlineComment indicates whether to ignore comments at the end of value and treat it as part of value.
Insensitive indicates whether the parser forces all section and key names to lowercase.
InsensitiveKeys indicates whether the parser forces all key names to lowercase.
InsensitiveSections indicates whether the parser forces all section to lowercase.
KeyValueDelimiterOnWrite is the delimiter that are used to separate key and value output. By default, it is "=".
KeyValueDelimiters is the sequence of delimiters that are used to separate key and value. By default, it is "=:".
Loose indicates whether the parser should ignore nonexistent files or return error.
PreserveSurroundedQuote indicates whether to preserve surrounded quote (single and double quotes).
ReaderBufferSize is the buffer size of the reader in bytes.
ShortCircuit indicates whether to ignore other configuration sources after loaded the first available configuration source.
SkipUnrecognizableLines indicates whether to skip unrecognizable lines that do not conform to key/value pairs.
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.
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.
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"
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.
func Empty(opts ...LoadOptions) *File
func LoadSources(opts LoadOptions, source interface{}, others ...interface{}) (_ *File, err error)
func github.com/spf13/viper.IniLoadOptions(in LoadOptions) viper.Option
func newFile(dataSources []dataSource, opts LoadOptions) *File
Section represents a config section.
Commentstringf*FileisRawSectionboolkeyList[]stringkeysmap[string]*KeykeysHashmap[string]stringnamestringrawBodystring
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.
Deprecated: Use "HasKey" instead.
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 section from given struct. It overwrites existing ones.
SetBody updates body content only if section is raw.
StrictMapTo maps section to given struct in strict mode,
which returns all possible error including value parsing error.
mapTo maps a section to object v.
mapToField maps the given value to the matching field of the given section.
The sectionIndex is the index (if non unique sections are enabled) to which the value should be added.
mapToSlice maps all sections with the same name and returns the new value.
The type of the Value must be a slice.
(*T) parseFieldName(raw, actual string) string(*T) reflectFrom(val reflect.Value) error
func (*File).ChildSections(name string) []*Section
func (*File).GetSection(name string) (*Section, error)
func (*File).NewRawSection(name, body string) (*Section, error)
func (*File).NewSection(name string) (*Section, error)
func (*File).Section(name string) *Section
func (*File).Sections() []*Section
func (*File).SectionsByName(name string) ([]*Section, error)
func (*File).SectionWithIndex(name string, index int) *Section
func (*Section).ChildSections() []*Section
func newSection(f *File, name string) *Section
func newKey(s *Section, name, val string) *Key
StructReflector is the interface implemented by struct types that can extract themselves into INI objects.
( T) ReflectINIStruct(*File) error
ValueMapper represents a mapping function for values, e.g. os.ExpandEnv
Package-Level Functions (total 32, in which 13 are exported)
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.
IsErrDelimiterNotFound returns true if the given error is an instance of ErrDelimiterNotFound.
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.
LoadSources allows caller to apply customized options for loading from data source(s).
LooseLoad has exactly same functionality as Load function
except it ignores nonexistent files instead of returning error.
MapTo maps data sources to given struct.
MapToWithMapper maps data sources to given struct with name mapper.
ReflectFrom reflects data sources from given struct.
ReflectFromWithMapper reflects data sources from given struct with name mapper.
ShadowLoad has exactly same functionality as Load function
except it allows have shadow keys.
StrictMapTo maps data sources to given struct in strict mode,
which returns all possible error including value parsing error.
StrictMapToWithMapper maps data sources to given struct with name mapper in strict mode,
which returns all possible error including value parsing error.
hasSurroundedQuote check if and only if the first and last characters
are quotes \" or \'.
It returns false if any other parts also contain same kind of quotes.
parseBool returns the boolean value represented by the string.
It accepts 1, t, T, TRUE, true, True, YES, yes, Yes, y, ON, on, On,
0, f, F, FALSE, false, False, NO, no, No, n, OFF, off, Off.
Any other value returns an error.
reflectSliceWithProperType does the opposite thing as setSliceWithProperType.
reflectWithProperType does the opposite thing as setWithProperType.
setSliceWithProperType sets proper values to slice based on its type.
setWithProperType sets proper value to field based on its type,
but it does not return error for failing parsing,
because we want to use default value that is already assigned to struct.
Package-Level Constants (total 4, in which 2 are exported)
Deprecated: Use "DefaultSection" instead.
DefaultSection is the name of 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.
Maximum allowed depth when recursively substituing variable names.
The pages are generated with Goldsv0.3.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.