package ini
import "gopkg.in/ini.v1"
Package ini provides INI file read and write functionality in Go.
Index ¶
- Constants
- Variables
- func MapTo(v, source interface{}, others ...interface{}) error
- func MapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error
- func ReflectFrom(cfg *File, v interface{}) error
- func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error
- func Version() string
- type File
- func Empty() *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 (f *File) Append(source interface{}, others ...interface{}) error
- func (f *File) DeleteSection(name string)
- func (f *File) GetSection(name string) (*Section, error)
- func (f *File) MapTo(v interface{}) error
- func (f *File) NewSection(name string) (*Section, error)
- func (f *File) NewSections(names ...string) (err error)
- func (f *File) ReflectFrom(v interface{}) error
- func (f *File) Reload() (err error)
- func (f *File) SaveTo(filename string) error
- func (f *File) SaveToIndent(filename, indent string) error
- func (f *File) Section(name string) *Section
- func (f *File) SectionStrings() []string
- func (f *File) Sections() []*Section
- func (f *File) WriteTo(w io.Writer) (int64, error)
- func (f *File) WriteToIndent(w io.Writer, indent string) (n int64, err error)
- type Key
- func (k *Key) Bool() (bool, error)
- func (k *Key) Duration() (time.Duration, error)
- func (k *Key) Float64() (float64, error)
- func (k *Key) Float64s(delim string) []float64
- func (k *Key) In(defaultVal string, candidates []string) string
- func (k *Key) InFloat64(defaultVal float64, candidates []float64) float64
- func (k *Key) InInt(defaultVal int, candidates []int) int
- func (k *Key) InInt64(defaultVal int64, candidates []int64) int64
- func (k *Key) InTime(defaultVal time.Time, candidates []time.Time) time.Time
- func (k *Key) InTimeFormat(format string, defaultVal time.Time, candidates []time.Time) time.Time
- func (k *Key) InUint(defaultVal uint, candidates []uint) uint
- func (k *Key) InUint64(defaultVal uint64, candidates []uint64) uint64
- func (k *Key) Int() (int, error)
- func (k *Key) Int64() (int64, error)
- func (k *Key) Int64s(delim string) []int64
- func (k *Key) Ints(delim string) []int
- func (k *Key) MustBool(defaultVal ...bool) bool
- func (k *Key) MustDuration(defaultVal ...time.Duration) time.Duration
- func (k *Key) MustFloat64(defaultVal ...float64) float64
- func (k *Key) MustInt(defaultVal ...int) int
- func (k *Key) MustInt64(defaultVal ...int64) int64
- func (k *Key) MustString(defaultVal string) string
- func (k *Key) MustTime(defaultVal ...time.Time) time.Time
- func (k *Key) MustTimeFormat(format string, defaultVal ...time.Time) time.Time
- func (k *Key) MustUint(defaultVal ...uint) uint
- func (k *Key) MustUint64(defaultVal ...uint64) uint64
- func (k *Key) Name() string
- func (k *Key) RangeFloat64(defaultVal, min, max float64) float64
- func (k *Key) RangeInt(defaultVal, min, max int) int
- func (k *Key) RangeInt64(defaultVal, min, max int64) int64
- func (k *Key) RangeTime(defaultVal, min, max time.Time) time.Time
- func (k *Key) RangeTimeFormat(format string, defaultVal, min, max time.Time) time.Time
- func (k *Key) SetValue(v string)
- func (k *Key) StrictFloat64s(delim string) ([]float64, error)
- func (k *Key) StrictInt64s(delim string) ([]int64, error)
- func (k *Key) StrictInts(delim string) ([]int, error)
- func (k *Key) StrictTimes(delim string) ([]time.Time, error)
- func (k *Key) StrictTimesFormat(format, delim string) ([]time.Time, error)
- func (k *Key) StrictUint64s(delim string) ([]uint64, error)
- func (k *Key) StrictUints(delim string) ([]uint, error)
- func (k *Key) String() string
- func (k *Key) Strings(delim string) []string
- func (k *Key) Time() (time.Time, error)
- func (k *Key) TimeFormat(format string) (time.Time, error)
- func (k *Key) Times(delim string) []time.Time
- func (k *Key) TimesFormat(format, delim string) []time.Time
- func (k *Key) Uint() (uint, error)
- func (k *Key) Uint64() (uint64, error)
- func (k *Key) Uint64s(delim string) []uint64
- func (k *Key) Uints(delim string) []uint
- func (k *Key) ValidFloat64s(delim string) []float64
- func (k *Key) ValidInt64s(delim string) []int64
- func (k *Key) ValidInts(delim string) []int
- func (k *Key) ValidTimes(delim string) []time.Time
- func (k *Key) ValidTimesFormat(format, delim string) []time.Time
- func (k *Key) ValidUint64s(delim string) []uint64
- func (k *Key) ValidUints(delim string) []uint
- func (k *Key) Validate(fn func(string) string) string
- func (k *Key) Value() string
- type LoadOptions
- type NameMapper
- type Section
- func (s *Section) DeleteKey(name string)
- func (s *Section) GetKey(name string) (*Key, error)
- func (s *Section) HasKey(name string) bool
- func (s *Section) HasValue(value string) bool
- func (s *Section) Haskey(name string) bool
- func (s *Section) Key(name string) *Key
- func (s *Section) KeyStrings() []string
- func (s *Section) Keys() []*Key
- func (s *Section) KeysHash() map[string]string
- func (s *Section) MapTo(v interface{}) error
- func (s *Section) Name() string
- func (s *Section) NewKey(name, val string) (*Key, error)
- func (s *Section) ParentKeys() []*Key
- func (s *Section) ReflectFrom(v interface{}) error
Constants ¶
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" )
Variables ¶
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" // Indicate whether to align "=" sign with spaces to produce pretty output // or reduce all possible spaces for compact format. PrettyFormat = true // Explicitly write DEFAULT section header DefaultHeader = false )
Functions ¶
func MapTo ¶
func MapTo(v, source interface{}, others ...interface{}) error
MapTo maps data sources to given struct.
func MapToWithMapper ¶
func MapToWithMapper(v interface{}, mapper NameMapper, source interface{}, others ...interface{}) error
MapTo maps data sources to given struct with name mapper.
func ReflectFrom ¶
ReflectFrom reflects data sources from given struct.
func ReflectFromWithMapper ¶
func ReflectFromWithMapper(cfg *File, v interface{}, mapper NameMapper) error
ReflectFrom reflects data sources from given struct with name mapper.
func Version ¶
func Version() string
Version returns current package version literal.
Types ¶
type File ¶
type File struct { // Should make things safe, but sometimes doesn't matter. BlockMode bool NameMapper // contains filtered or unexported fields }
File represents a combination of a or more INI file(s) in memory.
func Empty ¶
func Empty() *File
Empty returns an empty file object.
func InsensitiveLoad ¶
InsensitiveLoad has exactly same functionality as Load function except it forces all section and key names to be lowercased.
func Load ¶
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 ¶
func LoadSources(opts LoadOptions, source interface{}, others ...interface{}) (_ *File, err error)
func LooseLoad ¶
LooseLoad has exactly same functionality as Load function except it ignores nonexistent files instead of returning error.
func (*File) Append ¶
Append appends one or more data sources and reloads automatically.
func (*File) DeleteSection ¶
DeleteSection deletes a section.
func (*File) GetSection ¶
GetSection returns section by given name.
func (*File) MapTo ¶
MapTo maps file to given struct.
func (*File) NewSection ¶
NewSection creates a new section.
func (*File) NewSections ¶
NewSections creates a list of sections.
func (*File) ReflectFrom ¶
ReflectFrom reflects file from given struct.
func (*File) Reload ¶
Reload reloads and parses all data sources.
func (*File) SaveTo ¶
SaveTo writes content to file system.
func (*File) SaveToIndent ¶
SaveToIndent writes content to file system with given value indention.
func (*File) Section ¶
Section assumes named section exists and returns a zero-value when not.
func (*File) SectionStrings ¶
SectionStrings returns list of section names.
func (*File) Sections ¶
Section returns list of Section.
func (*File) WriteTo ¶
WriteTo writes file content into io.Writer.
func (*File) WriteToIndent ¶
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.
type Key ¶
type Key struct { Comment string // contains filtered or unexported fields }
Key represents a key under a section.
func (*Key) Bool ¶
Bool returns bool type value.
func (*Key) Duration ¶
Duration returns time.Duration type value.
func (*Key) Float64 ¶
Float64 returns float64 type value.
func (*Key) Float64s ¶
Float64s returns list of float64 divided by given delimiter. Any invalid input will be treated as zero value.
func (*Key) In ¶
In always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InFloat64 ¶
InFloat64 always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InInt ¶
InInt always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InInt64 ¶
InInt64 always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InTime ¶
InTime always parses with RFC3339 format and returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InTimeFormat ¶
InTimeFormat always parses with given format and returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InUint ¶
InUint always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) InUint64 ¶
InUint64 always returns value without error, it returns default value if error occurs or doesn't fit into candidates.
func (*Key) Int ¶
Int returns int type value.
func (*Key) Int64 ¶
Int64 returns int64 type value.
func (*Key) Int64s ¶
Int64s returns list of int64 divided by given delimiter. Any invalid input will be treated as zero value.
func (*Key) Ints ¶
Ints returns list of int divided by given delimiter. Any invalid input will be treated as zero value.
func (*Key) MustBool ¶
MustBool always returns value without error, it returns false if error occurs.
func (*Key) MustDuration ¶
MustDuration always returns value without error, it returns zero value if error occurs.
func (*Key) MustFloat64 ¶
MustFloat64 always returns value without error, it returns 0.0 if error occurs.
func (*Key) MustInt ¶
MustInt always returns value without error, it returns 0 if error occurs.
func (*Key) MustInt64 ¶
MustInt64 always returns value without error, it returns 0 if error occurs.
func (*Key) MustString ¶
MustString returns default value if key value is empty.
func (*Key) MustTime ¶
MustTime always parses with RFC3339 format and returns value without error, it returns zero value if error occurs.
func (*Key) MustTimeFormat ¶
MustTimeFormat always parses with given format and returns value without error, it returns zero value if error occurs.
func (*Key) MustUint ¶
MustUint always returns value without error, it returns 0 if error occurs.
func (*Key) MustUint64 ¶
MustUint64 always returns value without error, it returns 0 if error occurs.
func (*Key) Name ¶
Name returns name of key.
func (*Key) RangeFloat64 ¶
RangeFloat64 checks if value is in given range inclusively, and returns default value if it's not.
func (*Key) RangeInt ¶
RangeInt checks if value is in given range inclusively, and returns default value if it's not.
func (*Key) RangeInt64 ¶
RangeInt64 checks if value is in given range inclusively, and returns default value if it's not.
func (*Key) RangeTime ¶
RangeTime checks if value with RFC3339 format is in given range inclusively, and returns default value if it's not.
func (*Key) RangeTimeFormat ¶
RangeTimeFormat checks if value with given format is in given range inclusively, and returns default value if it's not.
func (*Key) SetValue ¶
SetValue changes key value.
func (*Key) StrictFloat64s ¶
StrictFloat64s returns list of float64 divided by given delimiter or error on first invalid input.
func (*Key) StrictInt64s ¶
StrictInt64s returns list of int64 divided by given delimiter or error on first invalid input.
func (*Key) StrictInts ¶
StrictInts returns list of int divided by given delimiter or error on first invalid input.
func (*Key) StrictTimes ¶
StrictTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter or error on first invalid input.
func (*Key) StrictTimesFormat ¶
StrictTimesFormat parses with given format and returns list of time.Time divided by given delimiter or error on first invalid input.
func (*Key) StrictUint64s ¶
StrictUint64s returns list of uint64 divided by given delimiter or error on first invalid input.
func (*Key) StrictUints ¶
StrictUints returns list of uint divided by given delimiter or error on first invalid input.
func (*Key) String ¶
String returns string representation of value.
func (*Key) Strings ¶
Strings returns list of string divided by given delimiter.
func (*Key) Time ¶
Time parses with RFC3339 format and returns time.Time type value.
func (*Key) TimeFormat ¶
TimeFormat parses with given format and returns time.Time type value.
func (*Key) Times ¶
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).
func (*Key) TimesFormat ¶
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).
func (*Key) Uint ¶
Uint returns uint type valued.
func (*Key) Uint64 ¶
Uint64 returns uint64 type value.
func (*Key) Uint64s ¶
Uint64s returns list of uint64 divided by given delimiter. Any invalid input will be treated as zero value.
func (*Key) Uints ¶
Uints returns list of uint divided by given delimiter. Any invalid input will be treated as zero value.
func (*Key) ValidFloat64s ¶
ValidFloat64s returns list of float64 divided by given delimiter. If some value is not float, then it will not be included to result list.
func (*Key) ValidInt64s ¶
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.
func (*Key) ValidInts ¶
ValidInts returns list of int divided by given delimiter. If some value is not integer, then it will not be included to result list.
func (*Key) ValidTimes ¶
ValidTimes parses with RFC3339 format and returns list of time.Time divided by given delimiter.
func (*Key) ValidTimesFormat ¶
ValidTimesFormat parses with given format and returns list of time.Time divided by given delimiter.
func (*Key) ValidUint64s ¶
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.
func (*Key) ValidUints ¶
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.
func (*Key) Validate ¶
Validate accepts a validate function which can return modifed result as key value.
func (*Key) Value ¶
Value returns raw value of key for performance purpose.
type LoadOptions ¶
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 }
type NameMapper ¶
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.
type Section ¶
type Section struct { Comment string // contains filtered or unexported fields }
Section represents a config section.
func (*Section) DeleteKey ¶
DeleteKey deletes a key from section.
func (*Section) GetKey ¶
GetKey returns key in section by given name.
func (*Section) HasKey ¶
HasKey returns true if section contains a key with given name.
func (*Section) HasValue ¶
HasValue returns true if section contains given raw value.
func (*Section) Haskey ¶
Haskey is a backwards-compatible name for HasKey.
func (*Section) Key ¶
Key assumes named Key exists in section and returns a zero-value when not.
func (*Section) KeyStrings ¶
KeyStrings returns list of key names of section.
func (*Section) Keys ¶
Keys returns list of keys of section.
func (*Section) KeysHash ¶
KeysHash returns keys hash consisting of names and values.
func (*Section) MapTo ¶
MapTo maps section to given struct.
func (*Section) Name ¶
Name returns name of Section.
func (*Section) NewKey ¶
NewKey creates a new key to given section.
func (*Section) ParentKeys ¶
ParentKeys returns list of keys of parent section.
func (*Section) ReflectFrom ¶
ReflectFrom reflects secion from given struct.
Source Files ¶
ini.go key.go parser.go section.go struct.go
- Version
- v1.17.0
- Published
- Jul 2, 2016
- Platform
- windows/amd64
- Imports
- 14 packages
- Last checked
- now –
Tools for package owners.