This commit is contained in:
张超
2025-09-18 17:58:19 +08:00
parent 5fd7411f9a
commit abd5962ae9
6 changed files with 6 additions and 12 deletions

View File

@@ -97,17 +97,6 @@ func LoadConfig(configPath string) (*Config, error) {
return nil, fmt.Errorf("配置解析失败: %w", err)
}
// 获取配置值
mysqlHost := viper.GetString("database.Host")
jwtSecretKey := viper.GetString("jwt.SecretKey")
serverPort := viper.GetInt("server.Port")
templateGlob := viper.GetString("project.TemplateGlob")
// 打印获取到的配置值
fmt.Printf("MySQL Host: %s\n", mysqlHost)
fmt.Printf("JWT Secret Key: %s\n", jwtSecretKey)
fmt.Printf("Server Port: %d\n", serverPort)
fmt.Printf("TemplateGlob: %s\n", templateGlob)
globalConfig = &cfg // 保存配置到全局变量
return &cfg, nil
}

View File

@@ -31,6 +31,7 @@ func main() {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
slog.SetDefault(logger)
slog.SetLogLoggerLevel(slog.LevelDebug)
slog.Info("初始化日志系统成功", "Defaultlogger", logger, "LogLevel", slog.LevelDebug)
// 3. 初始化数据库
models.InitDatabase(conf)

View File

@@ -45,6 +45,8 @@ func InitDatabase(conf *config.Config) {
if err != nil {
slog.Error("数据库连接失败", "error", err)
os.Exit(1)
} else {
slog.Info("数据库连接成功", "driver", conf.DataBase.Driver, "DSN", conf.DataBase.DSN)
}
DB = db

View File

@@ -1,3 +1,4 @@
<!-- templates/base.tmpl -->
<!DOCTYPE html>
<html>
<head>

View File

@@ -1,3 +1,4 @@
<!-- templates/about.tmpl -->
{{ define "header" }}
<header class="site-header">
<div class="container">

View File

@@ -99,4 +99,4 @@
{{ end }}
<!--继承基础模板内容-->
{{ template "base.html" . }}
{{ template "base.tmpl" . }}