更新底层架构

This commit is contained in:
2026-03-18 21:51:17 +08:00
parent b69c6ccbca
commit 68bea98b81
71 changed files with 5220 additions and 7619 deletions

View File

@@ -1,44 +1,36 @@
package server
import (
"NetworkAuth/web"
"io/fs"
"log"
"net/http"
"networkDev/web"
"github.com/gin-gonic/gin"
)
// ============================================================================
// 公共函数
// ============================================================================
// RegisterRoutes 聚合注册所有路由
func RegisterRoutes(router *gin.Engine) {
registerStaticRoutes(router)
registerFaviconRoute(router)
RegisterHomeRoutes(router)
RegisterAdminRoutes(router)
func RegisterRoutes(r *gin.Engine) {
registerStaticRoutes(r)
registerFaviconRoute(r)
RegisterInstallRoutes(r)
RegisterDefaultRoutes(r)
RegisterAdminRoutes(r)
}
// ============================================================================
// 私有函数
// ============================================================================
// registerStaticRoutes 注册静态资源路由
// 静态资源服务,将 /static/ 和 /assets/ 映射到嵌入的文件系统
func registerStaticRoutes(router *gin.Engine) {
func registerStaticRoutes(r *gin.Engine) {
if fsys, err := web.GetStaticFS(); err == nil {
// 为 /static/ 路径创建子文件系统
if staticSubFS, staticErr := fs.Sub(fsys, "static"); staticErr == nil {
router.StaticFS("/static", http.FS(staticSubFS))
r.StaticFS("/static", http.FS(staticSubFS))
} else {
log.Printf("创建静态资源子文件系统失败: %v", staticErr)
}
// 为 /assets/ 路径创建子文件系统
if assetsSubFS, assetsErr := fs.Sub(fsys, "assets"); assetsErr == nil {
router.StaticFS("/assets", http.FS(assetsSubFS))
r.StaticFS("/assets", http.FS(assetsSubFS))
} else {
log.Printf("创建资产资源子文件系统失败: %v", assetsErr)
}
@@ -48,9 +40,9 @@ func registerStaticRoutes(router *gin.Engine) {
}
// registerFaviconRoute 注册favicon路由
func registerFaviconRoute(router *gin.Engine) {
func registerFaviconRoute(r *gin.Engine) {
// 将 /favicon.ico 重定向到 /assets/favicon.svg
router.GET("/favicon.ico", func(c *gin.Context) {
r.GET("/favicon.ico", func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "/assets/favicon.svg")
})
}