config

package
v0.0.0-...-f1279a5 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2019 License: MIT Imports: 5 Imported by: 0

README

#配置文件包

1.配置文件采用默然加载的方式,配置文件路径固定不变(约定大于配置)

2.程序包用所有到的配置全部应用该包,从该包中进行获取,当影响程序运行的配置不存在时,由该包抛出异常并退出程序的运行

3.该包允许修改程序的配置并进行保存(可以通过后台更新的方式动态的配置配置文件不用重新启动服务器 热更新)

#使用注意: 1.程序的运行参数配置有各个包自己维护 2.程序包中统一添加init.go文件,在该文件中处理包中的文件的参数配置问题 3.所有的set和delete操作所做的修改会进行配置文件保存操作(包自动进行完成)

Documentation

Index

Constants

View Source
const (
	Config_Path = "./conf/app.conf" //默认的配置文件地址
)

Variables

This section is empty.

Functions

func Bool

func Bool(section, key string) (bool, error)

Bool returns bool type value.

func DEFAULTSECTION

func DEFAULTSECTION() string

返回默认配置节点

func DeleteKey

func DeleteKey(section, key string) (bool, error)

func DeleteSection

func DeleteSection(section string) (bool, error)

DeleteSection deletes the entire section by given name. It returns true if the section was deleted, and false if the section didn't exist.

func Float64

func Float64(section, key string) (float64, error)

Float64 returns float64 type value.

func GetKeyComments

func GetKeyComments(section, key string) (comments string)

GetKeyComments returns the comments of key in the given section. It returns an empty string(0 length) if the comments do not exist.

func GetKeyList

func GetKeyList(section string) []string

GetKeyList returns the list of all keys in give section in the same order in the file. It returns nil if given section does not exist.

func GetSection

func GetSection(section string) (map[string]string, error)

GetSection returns key-value pairs in given section. It section does not exist, returns nil and error.

func GetSectionComments

func GetSectionComments(section string) (comments string)

GetSectionComments returns the comments in the given section. It returns an empty string(0 length) if the comments do not exist.

func GetSectionList

func GetSectionList() []string

GetSectionList returns the list of all sections in the same order in the file.

func GetValue

func GetValue(section, key string) (string, error)

GetValue returns the value of key available in the given section. If the value needs to be unfolded (see e.g. %(google)s example in the GoConfig_test.go), then String does this unfolding automatically, up to _DEPTH_VALUES number of iterations. It returns an error and empty string value if the section does not exist, or key does not exist in DEFAULT and current sections.

func Int

func Int(section, key string) (int, error)

Int returns int type value.

func Int64

func Int64(section, key string) (int64, error)

Int64 returns int64 type value.

func MustBool

func MustBool(section, key string, defaultVal ...bool) bool

MustBool always returns value without error, it returns false if error occurs.

func MustFloat64

func MustFloat64(section, key string, defaultVal ...float64) float64

MustFloat64 always returns value without error, it returns 0.0 if error occurs.

func MustInt

func MustInt(section, key string, defaultVal ...int) int

MustInt always returns value without error, it returns 0 if error occurs.

func MustInt64

func MustInt64(section, key string, defaultVal ...int64) int64

MustInt64 always returns value without error, it returns 0 if error occurs.

func MustValue

func MustValue(section, key string, defaultVal ...string) string

MustValue always returns value without error. It returns empty string if error occurs, or the default value if given.

func MustValueArray

func MustValueArray(section, key, delim string) []string

MustValueArray always returns value array without error, it returns empty array if error occurs, split by delimiter otherwise.

func MustValueRange

func MustValueRange(section, key, defaultVal string, candidates []string) string

MustValueRange always returns value without error, it returns default value if error occurs or doesn't fit into range.

func MustValueSet

func MustValueSet(section, key string, defaultVal ...string) (string, bool, error)

MustValue always returns value without error, It returns empty string if error occurs, or the default value if given, and a bool value indicates whether default value is returned.

func SetKeyComments

func SetKeyComments(section, key, comments string) (bool, error)

SetKeyComments adds new section-key comments to the configuration. If comments are empty(0 length), it will remove its section-key comments! It returns true if the comments were inserted or removed, or returns false if the comments were overwritten. If the section does not exist in advance, it is created.

func SetSectionComments

func SetSectionComments(section, comments string) (bool, error)

SetSectionComments adds new section comments to the configuration. If comments are empty(0 length), it will remove its section comments! It returns true if the comments were inserted or removed, or returns false if the comments were overwritten.

func SetValue

func SetValue(section, key, value string) (bool, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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