config

package module
v0.0.0-...-53665f1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2016 License: MIT Imports: 5 Imported by: 4

README

Orivil config component

Install

go get -v gopkg.in/orivil/config.v0

Test

cd $GOPATH/src/gopkg.in/orivil/config.v0

go test example_test.go

Usage

see example_test.go

Contributors

https://github.com/orivil/config/graphs/contributors

License

Released under the MIT License.

Documentation

Overview

Package config for read the data form 'yaml' or 'json' file and copy the data to a struct.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}
Example
package main

import (
	"fmt"
	"gopkg.in/orivil/config.v0"
)

var configI18n = &struct {
	Languages map[string]string
}{
	// set default value
	Languages: map[string]string{
		"简体中文":    "zh-CN",
		"english": "en",
	},
}

func main() {
	// 1. new config instance
	cfg := config.NewConfig("./testdata")

	// 2. read file data to struct
	cfg.ReadStruct("i18n.yml", configI18n)

	// 3. get config data
	fmt.Println(configI18n.Languages)

}
Output:

map[简体中文:zh-CN english:en]

func NewConfig

func NewConfig(readDir string) *Config

func (*Config) ReadStruct

func (this *Config) ReadStruct(name string, struc interface{}) error

try to read the data form config file to struct, if the file not exist, it will be auto generated

func (*Config) ReloadAll

func (this *Config) ReloadAll()

func (*Config) ReloadFile

func (this *Config) ReloadFile(name string)

Jump to

Keyboard shortcuts

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