This commit is contained in:
2025-07-19 02:03:24 +08:00
commit ac6eeff8c9
44 changed files with 10305 additions and 0 deletions

44
internal/config/config.go Normal file
View File

@ -0,0 +1,44 @@
package config
import (
"github.com/spf13/viper"
"log"
)
type ServerConfig struct {
Port string
}
type MySQLConfig struct {
Host string
Port int
User string
Password string
Database string
}
type LogConfig struct {
Level string
Format string
Output string
}
var Conf struct {
Server ServerConfig
MySQL MySQLConfig
Log LogConfig
}
func InitConfig() {
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
log.Fatalf("读取配置失败: %v", err)
}
err = viper.Unmarshal(&Conf)
if err != nil {
log.Fatalf("解析配置失败: %v", err)
}
}