ini

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 18 Imported by: 23

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSection added in v1.0.27

func AddSection(sec *Section)

AddSection add a section to INI, overwrite existing section

func Clear added in v1.0.27

func Clear()

Clear clears the ini

func Copy added in v1.0.27

func Copy(src *Ini)

Copy copy section/entries from src ini, overwrite existing entries

func Get added in v1.0.27

func Get(sec, key string) string

Get get a value of the key from the section sec

func GetBool added in v1.0.27

func GetBool(sec, key string, defs ...bool) bool

GetBool get a bool value of the key from the section sec if not found or convert error, returns the first non-false value from defs.

func GetDuration added in v1.0.27

func GetDuration(sec, key string, defs ...time.Duration) time.Duration

GetDuration get a time.Duration value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func GetFloat added in v1.0.27

func GetFloat(sec, key string, defs ...float64) float64

GetFloat get a float value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func GetInt added in v1.0.27

func GetInt(sec, key string, defs ...int) int

GetInt get a int value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func GetInt64 added in v1.0.27

func GetInt64(sec, key string, defs ...int64) int64

GetInt64 get a int64 value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func GetSize added in v1.0.27

func GetSize(sec, key string, defs ...int64) int64

GetSize get a int64 size value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func GetString added in v1.0.27

func GetString(sec, key string, defs ...string) string

GetString get a string value of the key from the section sec if not found, returns the default defs[0] string value

func IsEmpty added in v1.0.27

func IsEmpty() bool

IsEmpty returns true if the Ini has no entry

func LoadData added in v1.0.27

func LoadData(r io.Reader, multiple ...bool) error

LoadData load INI from io.Reader if multiple = true, allow multiple entry with same key

func LoadFile added in v1.0.27

func LoadFile(path string, multiple ...bool) error

LoadFile load INI from file if multiple = true, allow multiple entry with same key

func LoadFileFS added in v1.0.27

func LoadFileFS(fsys fs.FS, path string, multiple ...bool) error

LoadFileFS load INI from file if multiple = true, allow multiple entry with same key

func Map added in v1.0.27

func Map() map[string]map[string]any

Map convert ini to map[string]map[string]any

func Merge added in v1.0.27

func Merge(src *Ini)

Merge merge entries from src ini, existing section/entries will be merged

func SectionNames added in v1.0.27

func SectionNames() []string

SectionNames returns the section array

func SetDefault added in v1.0.27

func SetDefault(ini *Ini)

SetDefault set the default Ini instance used by the package-level functions.

func String added in v1.0.27

func String() string

String write INI to the string

func StringMap added in v1.0.27

func StringMap() map[string]map[string]string

StringMap convert ini to map[string]map[string]string

func StringsMap added in v1.0.27

func StringsMap() map[string]map[string][]string

StringsMap convert ini to map[string]map[string][]string

func WriteData added in v1.0.27

func WriteData(w io.Writer) error

WriteData write INI to io.Writer

func WriteFile added in v1.0.27

func WriteFile(path string) error

WriteFile write INI to the file

Types

type Entry

type Entry struct {
	Value    string
	Comments []string
}

Entry ini entry

func Add added in v1.0.27

func Add(sec, key, value string, comments ...string) *Entry

Add add a key/value entry to the section sec

func Set added in v1.0.27

func Set(sec, key, value string, comments ...string) *Entry

Set set a key/value entry to the section sec

type EntryList

type EntryList = linkedlist.LinkedList[*Entry]

type Ini

type Ini struct {
	EOL string // End of Line
	// contains filtered or unexported fields
}

Ini INI file reader / writer

func Default added in v1.0.27

func Default() *Ini

Default returns the default Ini instance used by the package-level functions.

func NewIni

func NewIni() *Ini

NewIni create a Ini

func (*Ini) Add

func (ini *Ini) Add(sec, key, value string, comments ...string) *Entry

Add add a key/value entry to the section sec

func (*Ini) AddSection

func (ini *Ini) AddSection(section *Section)

AddSection add a section to INI, overwrite existing section

func (*Ini) Clear

func (ini *Ini) Clear()

Clear clears the ini

func (*Ini) Copy

func (ini *Ini) Copy(src *Ini)

Copy copy section/entries from src ini, overwrite existing entries

func (*Ini) Get

func (ini *Ini) Get(sec, key string) string

Get get a value of the key from the section sec

func (*Ini) GetBool

func (ini *Ini) GetBool(sec, key string, defs ...bool) bool

GetBool get a bool value of the key from the section sec if not found or convert error, returns the first non-false value from defs.

func (*Ini) GetDuration

func (ini *Ini) GetDuration(sec, key string, defs ...time.Duration) time.Duration

GetDuration get a time.Duration value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func (*Ini) GetEntry added in v1.0.27

func (ini *Ini) GetEntry(sec, key string) *Entry

GetEntry get a entry of key from the section sec

func (*Ini) GetFloat

func (ini *Ini) GetFloat(sec, key string, defs ...float64) float64

GetFloat get a float value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func (*Ini) GetInt

func (ini *Ini) GetInt(sec, key string, defs ...int) int

GetInt get a int value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func (*Ini) GetInt64

func (ini *Ini) GetInt64(sec, key string, defs ...int64) int64

GetInt64 get a int64 value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func (*Ini) GetSection

func (ini *Ini) GetSection(name string) *Section

GetSection return a section with the specified name or nil if section not exists

func (*Ini) GetSize

func (ini *Ini) GetSize(sec, key string, defs ...int64) int64

GetSize get a int64 size value of the key from the section sec if not found or convert error, returns the first non-zero value from defs.

func (*Ini) GetString

func (ini *Ini) GetString(sec, key string, defs ...string) string

GetString get a string value of the key from the section sec if not found, returns the first non-empty string value from defs.

func (*Ini) IsEmpty

func (ini *Ini) IsEmpty() bool

IsEmpty returns true if the Ini has no entry

func (*Ini) LoadData

func (ini *Ini) LoadData(r io.Reader, multiple ...bool) (err error)

LoadData load INI from io.Reader if multiple = true, allow multiple entry with same key

func (*Ini) LoadFile

func (ini *Ini) LoadFile(path string, multiple ...bool) error

LoadFile load INI from file if multiple = true, allow multiple entry with same key

func (*Ini) LoadFileFS

func (ini *Ini) LoadFileFS(fsys fs.FS, path string, multiple ...bool) error

LoadFileFS load INI from file if multiple = true, allow multiple entry with same key

func (*Ini) Map

func (ini *Ini) Map() map[string]map[string]any

Map convert ini to map[string]map[string]any

func (*Ini) Merge

func (ini *Ini) Merge(src *Ini)

Merge merge entries from src ini, existing section/entries will be merged

func (*Ini) NewSection

func (ini *Ini) NewSection(name string, comments ...string) *Section

NewSection create a section to INI, overwrite existing section

func (*Ini) RemoveSection

func (ini *Ini) RemoveSection(name string) (sec *Section)

RemoveSection remove a section from INI

func (*Ini) Section

func (ini *Ini) Section(name string) (sec *Section)

Section return a section with the specified name. if the section does not exists, create and add it to ini.

func (*Ini) SectionNames

func (ini *Ini) SectionNames() []string

SectionNames returns the section array

func (*Ini) Sections

func (ini *Ini) Sections() []*Section

Sections returns the section array

func (*Ini) Set

func (ini *Ini) Set(sec, key, value string, comments ...string) *Entry

Set set a key/value entry to the section sec

func (*Ini) String

func (ini *Ini) String() string

String write INI to the string

func (*Ini) StringMap

func (ini *Ini) StringMap() map[string]map[string]string

StringMap convert ini to map[string]map[string]string

func (*Ini) StringsMap

func (ini *Ini) StringsMap() map[string]map[string][]string

StringsMap convert ini to map[string]map[string][]string

func (*Ini) WriteData

func (ini *Ini) WriteData(w io.Writer) (err error)

WriteData write INI to io.Writer

func (*Ini) WriteFile

func (ini *Ini) WriteFile(path string) error

WriteFile write INI to the file

type Section

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

Section ini section

func GetSection added in v1.0.27

func GetSection(name string) *Section

GetSection return a section with the specified name or nil if section not exists

func NewSection

func NewSection(name string, comments ...string) *Section

NewSection create a section to INI, overwrite existing section

func RemoveSection added in v1.0.27

func RemoveSection(name string) *Section

RemoveSection remove a section from INI

func Sections

func Sections() []*Section

Sections returns the section array

func (*Section) Add

func (sec *Section) Add(key string, value string, comments ...string) *Entry

Add add a key/value entry to the section

func (*Section) Clear

func (sec *Section) Clear()

Clear clear the entries and comments

func (*Section) Comments

func (sec *Section) Comments() []string

Comments return the section's comment string array

func (*Section) Copy

func (sec *Section) Copy(src *Section)

Copy copy entries from src section, overwrite existing entries

func (*Section) Delete

func (sec *Section) Delete(key string)

Delete delete entries with key form the section

func (*Section) Get

func (sec *Section) Get(key string) string

Get get a value of the key from the section

func (*Section) GetBool

func (sec *Section) GetBool(key string, defs ...bool) bool

GetBool get a bool value of the key from the section if not found or convert error, returns the first non-false value from defs.

func (*Section) GetDuration

func (sec *Section) GetDuration(key string, defs ...time.Duration) time.Duration

GetDuration get a time.Duration value of the key from the section. if not found or convert error, returns the first non-zero value from defs.

func (*Section) GetEntries

func (sec *Section) GetEntries(key string) []*Entry

GetEntries get the key's entries from the section

func (*Section) GetEntry

func (sec *Section) GetEntry(key string) *Entry

GetEntry get the key's entry from the section

func (*Section) GetFloat

func (sec *Section) GetFloat(key string, defs ...float64) float64

GetFloat get a float value of the key from the section if not found or convert error, returns the first non-zero value from defs.

func (*Section) GetInt

func (sec *Section) GetInt(key string, defs ...int) int

GetInt get a int value of the key from the section if not found or convert error, returns the first non-zero value from defs.

func (*Section) GetInt64

func (sec *Section) GetInt64(key string, defs ...int64) int64

GetInt64 get a int64 value of the key from the section if not found or convert error, returns the first non-zero value from defs.

func (*Section) GetSize

func (sec *Section) GetSize(key string, defs ...int64) int64

GetSize get a int64 size value of the key from the section if not found or convert error, returns the first non-zero value from defs.

func (*Section) GetString

func (sec *Section) GetString(key string, defs ...string) string

GetString get a string value of the key from the section if not found, returns the default defs[0] string value

func (*Section) GetValues

func (sec *Section) GetValues(key string) []string

GetValues get the key's values from the section

func (*Section) Keys

func (sec *Section) Keys() []string

Keys return the section's key string array

func (*Section) Map

func (sec *Section) Map() map[string]any

Map return the section's entries key.(string)/value.(any) map

func (*Section) Merge

func (sec *Section) Merge(src *Section)

Merge merge entries from src section, existing entries will be merged

func (*Section) Name

func (sec *Section) Name() string

Name return the section's name

func (*Section) Remove

func (sec *Section) Remove(key string, value string) (e *Entry)

Remove remove a key/value entry from the section

func (*Section) Set

func (sec *Section) Set(key string, value string, comments ...string) *Entry

Set set a key/value entry to the section

func (*Section) String

func (sec *Section) String() string

String write section to string

func (*Section) StringMap

func (sec *Section) StringMap() map[string]string

StringMap return the section's entries key.(string)/value.(string) map

func (*Section) StringsMap

func (sec *Section) StringsMap() map[string][]string

StringsMap return the section's entries key.(string)/value.([]string) map

func (*Section) Write

func (sec *Section) Write(w io.Writer, eol string) error

Write output section to the writer

Jump to

Keyboard shortcuts

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