feat app 模块化启动

This commit is contained in:
2025-12-13 18:22:35 +08:00
parent 71d4e593c7
commit bc656247c9
41 changed files with 730 additions and 253 deletions

View File

@@ -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
}