ini

package
v2.9.9 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package ini is driver use INI format content as config source

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

Example
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)
Output:

Index

Examples

Constants

This section is empty.

Variables

Decoder the ini content decoder

Driver for ini

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

Encoder encode data to ini content

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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