ini

package
v1.2.15 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SepSection = "."
	DefTagName = "ini"
)

some default constants

Variables

This section is empty.

Functions

func Bool added in v1.2.0

func Bool(key string, defVal ...bool) bool

Bool get a bool value, if not found return default value

func Data added in v1.2.0

func Data() map[string]Section

Data get all data from default instance

func Delete added in v1.2.0

func Delete(key string) bool

Delete value by key

func Error added in v1.2.0

func Error() error

Error get

func Get added in v1.2.0

func Get(key string, defVal ...string) string

Get get a value by key string. you can use '.' split for get value in a special section

func GetValue added in v1.2.0

func GetValue(key string) (string, bool)

GetValue get a value by key string. you can use '.' split for get value in a special section

func HasKey added in v1.2.0

func HasKey(key string) bool

HasKey check key exists

func IgnoreCase added in v1.2.0

func IgnoreCase(opts *Options)

IgnoreCase for get/set value by key

func Int added in v1.2.0

func Int(key string, defVal ...int) int

Int get a int by key

func Int64 added in v1.2.0

func Int64(key string, defVal ...int64) int64

Int64 get a int value, if not found return default value

func IsEmpty added in v1.2.0

func IsEmpty() bool

IsEmpty config data is empty

func LoadData added in v1.2.0

func LoadData(data map[string]Section) error

LoadData load data map

func LoadExists added in v1.2.0

func LoadExists(files ...string) error

LoadExists load files, will ignore not exists

func LoadFiles added in v1.2.0

func LoadFiles(files ...string) error

LoadFiles load data from files

func LoadStrings added in v1.2.0

func LoadStrings(strings ...string) error

LoadStrings load data from strings

func MapStruct added in v1.2.0

func MapStruct(key string, ptr interface{}) error

MapStruct get config data and binding to the structure.

func ParseEnv added in v1.2.0

func ParseEnv(opts *Options)

ParseEnv will parse ENV key on get value Usage:

ini.WithOptions(ini.ParseEnv)

func ParseEnvValue added in v1.2.0

func ParseEnvValue(val string) (newVal string)

ParseEnvValue parse ENV var value from input string

func ParseVar added in v1.2.0

func ParseVar(opts *Options)

ParseVar on get value Usage:

ini.WithOptions(ini.ParseVar)

func Readonly added in v1.2.0

func Readonly(opts *Options)

Readonly setting Usage: ini.NewWithOptions(ini.Readonly)

func Reset added in v1.2.0

func Reset()

Reset all data for the default

func SectionKeys added in v1.2.0

func SectionKeys(withDefaultSection bool) (ls []string)

SectionKeys get all section names

func Set added in v1.2.0

func Set(key string, val interface{}, section ...string) error

Set a value to the section by key. if section is empty, will set to default section

func String added in v1.2.0

func String(key string, defVal ...string) string

String get a string by key

func StringMap added in v1.2.0

func StringMap(name string) map[string]string

StringMap get a section data map

func Strings added in v1.2.0

func Strings(key string, sep ...string) []string

Strings get a string array, by split a string

func Uint added in v1.2.0

func Uint(key string, defVal ...uint) uint

Uint get a uint value, if not found return default value

func WithOptions added in v1.2.0

func WithOptions(opts ...func(*Options))

WithOptions apply some options

Types

type Ini added in v1.2.0

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

Ini config data manager

func Default added in v1.2.0

func Default() *Ini

Default config instance

func New added in v1.2.0

func New() *Ini

New a config instance, with default options

func NewWithOptions added in v1.2.0

func NewWithOptions(opts ...func(*Options)) *Ini

NewWithOptions new a instance and with some options Usage: ini.NewWithOptions(ini.ParseEnv, ini.Readonly)

func (*Ini) Bool added in v1.2.0

func (c *Ini) Bool(key string, defVal ...bool) (value bool)

Bool Looks up a value for a key in this section and attempts to parse that value as a boolean, along with a boolean result similar to a map lookup. of following(case insensitive):

  • true
  • false
  • yes
  • no
  • off
  • on
  • 0
  • 1

The `ok` boolean will be false in the event that the value could not be parsed as a bool

func (*Ini) Data added in v1.2.0

func (c *Ini) Data() map[string]Section

Data get all data

func (*Ini) DefSection added in v1.2.0

func (c *Ini) DefSection() string

DefSection get default section name

func (*Ini) DelSection added in v1.2.0

func (c *Ini) DelSection(name string) (ok bool)

DelSection del section by name

func (*Ini) Delete added in v1.2.0

func (c *Ini) Delete(key string) (ok bool)

Delete value by key

func (*Ini) Error added in v1.2.0

func (c *Ini) Error() error

Error get

func (*Ini) Get added in v1.2.0

func (c *Ini) Get(key string, defVal ...string) string

Get a value by key string. you can use '.' split for get value in a special section

func (*Ini) GetValue added in v1.2.0

func (c *Ini) GetValue(key string) (val string, ok bool)

GetValue a value by key string. you can use '.' split for get value in a special section

func (*Ini) HasKey added in v1.2.0

func (c *Ini) HasKey(key string) (ok bool)

HasKey check key exists

func (*Ini) HasSection added in v1.2.0

func (c *Ini) HasSection(name string) bool

HasSection has section

func (*Ini) Int added in v1.2.0

func (c *Ini) Int(key string, defVal ...int) (value int)

Int get a int value, if not found return default value

func (*Ini) Int64 added in v1.2.0

func (c *Ini) Int64(key string, defVal ...int64) (value int64)

Int64 get a int value, if not found return default value

func (*Ini) IsEmpty added in v1.2.0

func (c *Ini) IsEmpty() bool

IsEmpty config data is empty

func (*Ini) LoadData added in v1.2.0

func (c *Ini) LoadData(data map[string]Section) (err error)

LoadData load data map

func (*Ini) LoadExists added in v1.2.0

func (c *Ini) LoadExists(files ...string) (err error)

LoadExists load files, will ignore not exists

func (*Ini) LoadFiles added in v1.2.0

func (c *Ini) LoadFiles(files ...string) (err error)

LoadFiles load data from files

func (*Ini) LoadStrings added in v1.2.0

func (c *Ini) LoadStrings(strings ...string) (err error)

LoadStrings load data from strings

func (*Ini) MapStruct added in v1.2.0

func (c *Ini) MapStruct(key string, ptr interface{}) error

MapStruct get config data and binding to the structure. Usage:

user := &Db{}
ini.MapStruct("user", &user)

func (*Ini) MapTo added in v1.2.0

func (c *Ini) MapTo(ptr interface{}) error

MapTo struct pointer WIP

func (*Ini) NewSection added in v1.2.0

func (c *Ini) NewSection(name string, values map[string]string) (err error)

NewSection add new section data, existed will be replace

func (*Ini) Options added in v1.2.0

func (c *Ini) Options() Options

Options get options info. Notice: return is value. so, cannot change options

func (*Ini) PrettyJSON added in v1.2.0

func (c *Ini) PrettyJSON() string

PrettyJSON translate to pretty JSON string

func (*Ini) Reset added in v1.2.0

func (c *Ini) Reset()

Reset all data

func (*Ini) Section added in v1.2.0

func (c *Ini) Section(name string) Section

Section get a section data map. is alias of StringMap()

func (*Ini) SectionKeys added in v1.2.0

func (c *Ini) SectionKeys(withDefaultSection bool) (ls []string)

SectionKeys get all section names

func (*Ini) Set added in v1.2.0

func (c *Ini) Set(key string, val interface{}, section ...string) (err error)

Set a value to the section by key. if section is empty, will set to default section

func (*Ini) SetSection added in v1.2.0

func (c *Ini) SetSection(name string, values map[string]string) (err error)

SetSection if not exist, add new section. If exist, will merge to old section.

func (*Ini) String added in v1.2.0

func (c *Ini) String(key string, defVal ...string) string

String like Get method

func (*Ini) StringMap added in v1.2.0

func (c *Ini) StringMap(name string) (mp map[string]string)

StringMap get a section data map

func (*Ini) Strings added in v1.2.0

func (c *Ini) Strings(key string, sep ...string) (ss []string)

Strings get a string array, by split a string

func (*Ini) Uint added in v1.2.0

func (c *Ini) Uint(key string, defVal ...uint) (value uint)

Uint get a int value, if not found return default value

func (*Ini) WithOptions added in v1.2.0

func (c *Ini) WithOptions(opts ...func(*Options))

WithOptions apply some options

func (*Ini) WriteTo added in v1.2.0

func (c *Ini) WriteTo(out io.Writer) (n int64, err error)

WriteTo out an INI File representing the current state to a writer.

func (*Ini) WriteToFile added in v1.2.0

func (c *Ini) WriteToFile(file string) (int64, error)

WriteToFile write config data to a file

type Options added in v1.2.0

type Options struct {
	// Readonly set to read-only mode. default False
	Readonly bool
	// ParseEnv parse ENV var name. default True
	ParseEnv bool
	// ParseVar parse variable reference "%(varName)s". default False
	ParseVar bool
	// TagName for binding struct
	TagName string

	// VarOpen var left open char. default "%("
	VarOpen string
	// VarClose var right close char. default ")s"
	VarClose string

	// IgnoreCase ignore key name case. default False
	IgnoreCase bool
	// DefSection default section name. default "__default", it's allow empty string.
	DefSection string
	// SectionSep sep char for split key path. default ".", use like "section.subKey"
	SectionSep string
}

Options for config

func GetOptions added in v1.2.0

func GetOptions() Options

GetOptions get options info. Notice: return is value. so, cannot change Ini instance

type Section added in v1.2.0

type Section map[string]string

Section in INI config

Directories

Path Synopsis
Package parser is a Parser for parse INI format content to golang data There are example data: # comments name = inhere age = 28 debug = true hasQuota1 = 'this is val' hasQuota2 = "this is val1" shell = ${SHELL} noEnv = ${NotExist|defValue} ; array in def section tags[] = a tags[] = b tags[] = c ; comments [sec1] key = val0 some = value stuff = things ; array in section types[] = x types[] = y how to use, please see examples:
Package parser is a Parser for parse INI format content to golang data There are example data: # comments name = inhere age = 28 debug = true hasQuota1 = 'this is val' hasQuota2 = "this is val1" shell = ${SHELL} noEnv = ${NotExist|defValue} ; array in def section tags[] = a tags[] = b tags[] = c ; comments [sec1] key = val0 some = value stuff = things ; array in section types[] = x types[] = y how to use, please see examples:

Jump to

Keyboard shortcuts

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