瀏覽代碼

:add config 增加 结构体 解析

fly 1 年之前
父節點
當前提交
9e2e84ef9e
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 4 0
      config/config.go
  2. 4 0
      config/object.go

+ 4 - 0
config/config.go

@@ -63,6 +63,10 @@ func Set(module, key string, value any) {
 	viper.Set(module+"."+key, value)
 }
 
+func Unmarshal(module, key string, value any) error {
+	return viper.UnmarshalKey(module+"."+key, value)
+}
+
 func ReadConfigAndFileExist() (bool, error) {
 	if err := viper.ReadInConfig(); err != nil {
 		if _, ok := err.(viper.ConfigFileNotFoundError); ok {

+ 4 - 0
config/object.go

@@ -68,6 +68,10 @@ func (c *config) Set(module, key string, value any) {
 	c.Viper.Set(module+"."+key, value)
 }
 
+func (c *config) Unmarshal(module, key string, value any) error {
+	return c.Viper.UnmarshalKey(module+"."+key, value)
+}
+
 func (c *config) ReadConfigAndFileExist() (bool, error) {
 	if err := c.Viper.ReadInConfig(); err != nil {
 		if _, ok := err.(viper.ConfigFileNotFoundError); ok {