ini – Simple INI Format Config Parse with Marshal and Unmarshal

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/ini

Getting Started

func main() {
  	iniText := `app_name = go-zoox web

# possible values: DEBUG, INFO, WARNING, ERROR, FATAL
log_level = DEBUG

[mysql]
ip = 127.0.0.1
port = 3306
user = zero
password = 123456
database = go-zoox

[redis]
ip = 127.0.0.1
port = 6379`

	type Config struct {
		AppName  string `ini:"app_name"`
		LogLevel string `ini:"log_level"`
		Mysql    struct {
			IP       string `ini:"ip"`
			Port     int    `ini:"port"`
			User     string `ini:"user"`
			Password string `ini:"password"`
			Database string `ini:"database"`
		} `ini:"mysql"`
		Redis struct {
			IP   string `ini:"ip"`
			Port int    `ini:"port"`
		} `ini:"redis"`
	}

	var config Config
	if err := Unmarshal([]byte(iniText), &config); err != nil {
		t.Error(err)
	} else {
		j, _ := json.MarshalIndent(config, "", "  ")
		t.Log(string(j))
	}
}

License

GoZoox is released under the MIT License.

GitHub

View Github