config: github.com/gookit/config/ini Index | Examples | Files

package ini

import "github.com/gookit/config/ini"

Package ini is driver use INI format content as config source

about ini parse, please see https://github.com/gookit/ini/parser

Code:

config.WithOptions(config.ParseEnv)

// add Decoder and Encoder
config.AddDriver(Driver)
// Or
// config.SetEncoder(config.Ini, ini.Encoder)

err := config.LoadFiles("testdata/ini_base.ini")
if err != nil {
    panic(err)
}

// fmt.Printf("config data: \n %#v\n", config.Data())

err = config.LoadFiles("testdata/ini_other.ini")
// config.LoadFiles("testdata/ini_base.ini", "testdata/ini_other.ini")
if err != nil {
    panic(err)
}

// fmt.Printf("config data: \n %#v\n", config.Data())
fmt.Print("get config example:\n")

name := config.String("name")
fmt.Printf("get string\n - val: %v\n", name)

// NOTICE: ini is not support array

map1 := config.StringMap("map1")
fmt.Printf("get map\n - val: %#v\n", map1)

val0 := config.String("map1.key")
fmt.Printf("get sub-value by path 'map.key'\n - val: %v\n", val0)

// can parse env name(ParseEnv: true)
fmt.Printf("get env 'envKey' val: %s\n", config.String("envKey", ""))
fmt.Printf("get env 'envKey1' val: %s\n", config.String("envKey1", ""))

// set value
_ = config.Set("name", "new name")
name = config.String("name")
fmt.Printf("set string\n - val: %v\n", name)

Index

Examples

Package Files

ini.go

Variables

var Decoder config.Decoder = parser.Decode

Decoder the ini content decoder

var Driver = &iniDriver{config.Ini}

Driver for ini

var Encoder config.Encoder = func(ptr interface{}) (out []byte, err error) {
    return parser.Encode(ptr)
}

Encoder encode data to ini content

Package ini imports 2 packages (graph). Updated 2019-06-11. Refresh now. Tools for package owners.