config

package
v0.0.0-...-0cfefd3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

README

Golang Tools Config

Golang Tools Config Support:

  • Json
  • Yaml
  • Toml
  • Xml

Example

json
	// 实例
	type Instance struct {
		Name 	string
		Path	string
		Cmd		[]string
		User	string
	}

	// 配置
	type Config struct {
		Port int
		Instance []Instance
	}

	var conf Config
	err := config.New("conf.json", &conf)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(conf)

Run:

go run ../example/config/main.go -c ../example/config/conf.json
{8080 [{gitbook /gitbook [ll ls] dingdayu}]}

请注意路径!

参见 example/config/main.go

xml
	// 实例
	type Instance struct {
		Name 	string
		Path	string
		Cmd		[]string
		User	string
	}

	// 配置
	type Config struct {
		Port int
		Instance []Instance
	}

	var conf Config
	err := config.New("conf.xml", &conf)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(conf)

参加 example/config/main.go

toml
	// 实例
	type Instance struct {
		Name 	string
		Path	string
		Cmd		[]string
		User	string
	}

	// 配置
	type Config struct {
		Port int
		Instance []Instance
	}

	var conf Config
	err := config.New("conf.toml", &conf)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(conf)

参见 example/config/main.go

yaml
	// 实例
	type Instance struct {
		Name 	string
		Path	string
		Cmd		[]string
		User	string
	}

	// 配置
	type Config struct {
		Port int
		Instance []Instance
	}

	var conf Config
	err := config.New("conf.yaml", &conf)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(conf)

参见 example/config/main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(f string, c interface{}) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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