config

package module
v0.0.0-...-3b5eb13 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2014 License: Apache-2.0 Imports: 9 Imported by: 0

README

goconfig

##About Go package:The INI configuration file read and write. 中文文档

##Features

##Example

config.ini
appname = "WishCMS"

[Demo]
key1 = "Let"

todo = "恩恩"

中国 = "China"

test = ""China"

[Hi]
name = "chris"

age = "23"

nu = "-1"

[auto]
- = "config"
- = "hello"
- = "go"
- = "conf"
- = "demo"

[New]
Qint = "123"

======================= ##code:

c, _ := LoadConfigFile("testing/config1.ini", "testing/config2.ini")//加载多个配置

_, _ := c.Get("Demo::key1")//获取Demo组key1值

_, _ := c.Get("appname")//获取默认分组 appname值

_, _ := c.GetGroup("Demo")//获取Demo分组所有配置

c.Set("New", "key1", "999")//设置New组key1值为999

_, _ := c.Int("New::Qint")//获取New组Qint值并转换为int

_ := c.Qint64("New::Qini64", 9)//快速获取值并设置默认值

_, _ := c.Get("auto::#1")//获取auto自增配置组第一个配置项值 config

c.Reload() //重载配置

ok := SaveConfig(c, "save.ini")//保存配置

c, _ := LoadConfigFile("testing/config1.ini")//加载一个配置

##Install go get github.com/0x55/goconfig

include config package:

import (
	"github.com/0x55/goconfig"
)

##License This project is under Apache v2 License.

Documentation

Index

Constants

View Source
const (
	DEFAULT_GROUP = "default"
	//group未找到
	GROUP_NOT_FOUND = iota
	//选项未找到
	KEY_NOT_FOUND
	//组错误
	GROUP_FAIL
	//解析失败
	COULD_NOT_PARSE
)

Variables

This section is empty.

Functions

func SaveConfig

func SaveConfig(c *Config, filename string) (err error)

Types

type Config

type Config struct {
	Mode bool
	// contains filtered or unexported fields
}

func LoadConfigFile

func LoadConfigFile(file string, more ...string) (c *Config, err error)

func (*Config) AppendConfigFiles

func (c *Config) AppendConfigFiles(files ...string) error

func (*Config) Bool

func (c *Config) Bool(key string) (bool, error)

/////////////////////获取指定类型的配置///////////////////////

func (*Config) Del

func (c *Config) Del(key string) bool

*

  • 删除配置项

func (*Config) DelGroup

func (c *Config) DelGroup(group string) bool

*

  • 删除一组配置项

func (*Config) Float64

func (c *Config) Float64(key string) (float64, error)

func (*Config) Get

func (c *Config) Get(key string) (string, error)

*

  • 获取配置

func (*Config) GetGroup

func (c *Config) GetGroup(group string) (map[string]string, error)

*

  • 获取一组配置

func (*Config) Int

func (c *Config) Int(key string) (int, error)

func (*Config) Int64

func (c *Config) Int64(key string) (int64, error)

func (*Config) Qbool

func (c *Config) Qbool(key string, def bool) bool

func (*Config) Qfloat64

func (c *Config) Qfloat64(key string, def float64) float64

func (*Config) Qint

func (c *Config) Qint(key string, def int) int

func (*Config) Qint64

func (c *Config) Qint64(key string, def int64) int64

func (*Config) Reload

func (c *Config) Reload() (err error)

*

  • 重载配置文件

func (*Config) Set

func (c *Config) Set(group, key, val string)

*

  • 设置配置

Jump to

Keyboard shortcuts

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