ini

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 7 Imported by: 2

README

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.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.0.4"

Version is the current version of this package.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the ini data of the given struct pointer.

func Parse added in v1.0.3

func Parse(bytes []byte) (map[string]interface{}, error)

Parse parses the ini data and returns a map.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal parses the ini data and stores the result in the value pointed to by v.

Types

This section is empty.

Jump to

Keyboard shortcuts

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