refactor(后端): 删除gin请求日志,优化代码路径
部署开发环境 / deploy-dev (push) Successful in 2m0s

This commit is contained in:
2026-06-03 13:02:40 +08:00
parent f9e099bc24
commit 1505226628
7 changed files with 20 additions and 19 deletions
+1 -1
View File
@@ -1,8 +1,8 @@
package controller
import (
"dypid/global"
"dypid/internal/db"
"dypid/internal/global"
"fmt"
"net/http"
"strings"
+1 -1
View File
@@ -1,8 +1,8 @@
package controller
import (
"dypid/global"
"dypid/internal/db"
"dypid/internal/global"
"net/http"
"strconv"
+2 -2
View File
@@ -1,8 +1,8 @@
package db
import (
"dypid/config"
"dypid/global"
"dypid/internal/config"
"dypid/internal/global"
"fmt"
"github.com/redis/go-redis/v9"
+7 -7
View File
@@ -1,8 +1,8 @@
package api
package service
import (
"dypid/global"
"dypid/internal/controller"
"dypid/internal/global"
"embed"
"fmt"
"io/fs"
@@ -11,7 +11,7 @@ import (
"github.com/gin-gonic/gin"
)
func RegRoutes(r *gin.Engine) {
func RegAPIService(r *gin.Engine) {
g := r.Group("/api") //初始化路由组 /api/xxxx
{
g.GET("/test", func(context *gin.Context) {
@@ -35,16 +35,16 @@ func RegRoutes(r *gin.Engine) {
}
}
func RegWebService(r *gin.Engine, webDir embed.FS) {
assets, _ := fs.Sub(webDir, "web/dist/assets")
func RegWebService(r *gin.Engine, webFiles embed.FS) {
assets, _ := fs.Sub(webFiles, "web/dist/assets")
r.StaticFS("/assets", http.FS(assets))
icon, _ := fs.ReadFile(webDir, "web/dist/favicon.ico")
icon, _ := fs.ReadFile(webFiles, "web/dist/favicon.ico")
r.GET("/favicon.ico", func(c *gin.Context) {
c.Data(200, "image/x-icon", icon)
})
indexHtml, _ := fs.ReadFile(webDir, "web/dist/index.html")
indexHtml, _ := fs.ReadFile(webFiles, "web/dist/index.html")
r.NoRoute(func(c *gin.Context) {
c.Data(200, "text/html; charset=utf-8", indexHtml)
})
+9 -8
View File
@@ -1,9 +1,9 @@
package main
import (
"dypid/api"
"dypid/config"
"dypid/internal/config"
"dypid/internal/db"
"dypid/internal/service"
"embed"
"fmt"
@@ -12,22 +12,23 @@ import (
)
//go:embed web/dist/*
var webDir embed.FS
var webFiles embed.FS
func main() {
config.InitConfig()
db.InitRedis()
db.InitLocalDB()
//初始化一个http服务对象
gin.SetMode(config.APPConfig.RunMode)
r := gin.Default()
r := gin.New()
r.Use(gin.Recovery())
r.Use(cors.Default()) //跨域设置
//跨域设置
r.Use(cors.Default())
//注册网页服务(Vue
api.RegWebService(r, webDir)
service.RegWebService(r, webFiles)
//注册API接口
api.RegRoutes(r)
service.RegAPIService(r)
// 监听并在 0.0.0.0:8080 上启动服务
fmt.Printf("服务器正在运行:http://%s\n", config.APPConfig.Host)