README
¶
一个简单的 toml/yaml 配置读取包
这是一个非常简单的配置读取包,功能非常单一,使用非常简单;
安装
gitee.com/zhucheer/cfg
使用
cfgHandler, _ := cfg.New("./config.toml") //设置配置文件地址
value := cfgHandler.GetInt("database.connection_max") //读取toml配置节点
Nacos 支持
1.首先,我们需要在项目中初始化 Nacos Client。
clientConfig := *constant.NewClientConfig(
constant.WithNotLoadCacheAtStart(true),
constant.WithLogDir("./nacos/log"),
constant.WithCacheDir("./nacos/cache"),
constant.WithRotateTime("1h"),
constant.WithMaxAge(6),
constant.WithLogLevel("info"),
constant.WithNamespaceId(""),
constant.WithUsername(),
constant.WithPassword()
)
configClient, _ := clients.NewConfigClient(
vo.NacosClientParam{
ClientConfig: &clientConfig,
ServerConfigs: []constant.ServerConfig{
{
IpAddr: "106.55.145.120",
ContextPath: "/nacos",
Port: 8848,
Scheme: "http",
},
},
},
)
// clientConfig,configClient可以配置成全局变量,在需要使用nacos的地方直接调用
2.将nacos配置实例化到cfg包的handler
handler := NewNacos(&NacosBase{
ConfigClient: configClient,
GroupId: "orange10",
DataId: "config.toml",
})
key := handler2.GetString("app.name")
Documentation
¶
Index ¶
- type Handler
- func New(filePath string) *Handler
- func NewFile(filePath string, dynamic bool) *Handler
- func NewNacos(baseInfo *NacosBase) *Handler
- func NewTomlData(content string) *Handler
- func NewYamlData(content string) *Handler
- func ReloadTomlData(content string) (*Handler, error)
- func ReloadYamlData(content string) (*Handler, error)
- func (c *Handler) Exists(parse string) bool
- func (c *Handler) GetBool(key string) bool
- func (c *Handler) GetDuration(key string) time.Duration
- func (c *Handler) GetInt(key string) int
- func (c *Handler) GetInt64(key string) int64
- func (c *Handler) GetMap(parse string) map[string]interface{}
- func (c *Handler) GetSliceInt(key string) []int
- func (c *Handler) GetSliceInt64(key string) []int64
- func (c *Handler) GetSliceString(key string) []string
- func (c *Handler) GetString(key string) string
- func (c *Handler) ParseNode(parse string) (ret interface{})
- func (c *Handler) ReloadFile() *Handler
- func (c *Handler) StartDynamic() *Handler
- func (c *Handler) UnmarshalKey(key string, rawVal interface{}) error
- type NacosBase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶ added in v0.1.3
配置对象
func NewNacos ¶ added in v0.1.5
NewNacosData get a cfg handler by toml string content nacos目前没有toml支持,暂时统一使用yaml格式
func NewTomlData ¶ added in v0.1.1
NewTomlData get a cfg handler by toml string content
func NewYamlData ¶ added in v0.1.1
NewTomlData get a cfg handler by toml string content
func ReloadTomlData ¶ added in v0.1.8
ReloadTomlData get a cfg handler by toml string content
func ReloadYamlData ¶ added in v0.1.7
ReloadYamlData get a cfg handler by toml string content
func (*Handler) GetDuration ¶ added in v0.1.3
GetDuration get config time.Duration type
func (*Handler) GetSliceInt ¶ added in v0.1.3
GetSliceInt get slice int type
func (*Handler) GetSliceInt64 ¶ added in v0.1.3
GetSliceInt64 get slice int64 type
func (*Handler) GetSliceString ¶ added in v0.1.3
GetSliceString get slice string type
func (*Handler) ReloadFile ¶ added in v0.2.0
ReloadFile get a cfg handler by file path reload config
func (*Handler) StartDynamic ¶ added in v0.2.0
StartDynamic after start listen config file change
func (*Handler) UnmarshalKey ¶ added in v0.2.0
UnmarshalKey Unmarshal config to struct
type NacosBase ¶ added in v0.1.5
type NacosBase struct { ConfigClient config_client.IConfigClient GroupId string DataId string }