Эх сурвалжийг харах

:add config 增加 结构体 解析

fly 1 жил өмнө
parent
commit
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 {