feat app 模块化启动
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/spf13/viper"
|
||||
"strings"
|
||||
@@ -28,11 +29,14 @@ func LoadConfig[T any](configDir string, configPtr *T) (*T, error) {
|
||||
v.SetConfigType("yaml")
|
||||
|
||||
if err := v.ReadInConfig(); err != nil {
|
||||
return nil, fmt.Errorf("读取配置失败: %w", err)
|
||||
return nil, fmt.Errorf("failed to read config: %w", err)
|
||||
}
|
||||
|
||||
if err := v.Unmarshal(&configPtr); err != nil {
|
||||
return nil, fmt.Errorf("解析配置失败: %w", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal config: %w", err)
|
||||
}
|
||||
|
||||
marshal, _ := json.Marshal(configPtr)
|
||||
fmt.Printf("Configuration loading completed: %v\n", string(marshal))
|
||||
return configPtr, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user