settings

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT, MIT Imports: 5 Imported by: 0

README

go-settings

供Go语言使用的配置文件管理器

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind(bindKey, trueKey string)

Bind 将bindKey与trueKey进行绑定,使bindKey单向映射为trueKey 一个trueKey可映射多个bindKey

func Exsit

func Exsit(key string) bool

Exsit 判断全局默认配置中是否存在 key

func Get

func Get(key string) string

Get 获取全局默认配置中 key 的值

func GetInt64

func GetInt64(key string) int64

GetInt64 获取全局默认配置中 key 的值,并转换为int64,转换失败会触发panic

func ImportLines

func ImportLines(data []string) error

ImportLines 从 []string 向全局默认配置中导入数据

func JoinClassNameAndKey

func JoinClassNameAndKey(className, subKey string) (key string)

JoinClassNameAndKey 将class_name与sub_key用标准class分隔符连接起来

func Set

func Set(key, value string)

Set 设置全局默认配置中 key 的值

func SetDefault

func SetDefault(key, value string)

SetDefault 设置全局默认配置中 key 的默认值 不会覆盖既有值

func ToString

func ToString() string

ToString 将全局默认配置输出为格式化的字符串

Types

type Settings

type Settings struct {
	// contains filtered or unexported fields
}

Settings 基于文本的配置管理器 忽略键名大小写 可设置键名绑定

func GetChild

func GetChild(className string) *Settings

GetChild 获取子类的Settings

func (*Settings) Bind

func (s *Settings) Bind(bindKey, trueKey string)

Bind 绑定 建立bindKey到trueKey的映射 一个bindKey只可映一个trueKey 一个trueKey可接受多个bindKey的映射

func (Settings) Exsit

func (s Settings) Exsit(key string) bool

Exsit 判断 key 是否存在

func (Settings) Get

func (s Settings) Get(key string) (value string)

Get 获取配置,key不存在则触发panic

func (*Settings) GetChild

func (s *Settings) GetChild(className string) (child *Settings)

GetChild 获取子类的Settings

func (Settings) GetInt64

func (s Settings) GetInt64(key string) int64

GetInt64 获取配置,且尝试转换为int64,转换失败会触发panic

func (*Settings) ImportLines

func (s *Settings) ImportLines(data []string) error

ImportLines 从 []string 导入数据 每行应该遵从以下格式: key = value

func (*Settings) Set

func (s *Settings) Set(key, value string)

Set 配置

func (*Settings) SetDefault

func (s *Settings) SetDefault(key, value string)

SetDefault 设置默认值,不会覆盖既有值

func (Settings) ToString

func (s Settings) ToString() string

ToString 输出为字符串

Jump to

Keyboard shortcuts

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