// routes/static.go // 静态资源路由 package routes import ( "os" "path/filepath" "github.com/gin-gonic/gin" ) // getStaticPath 获取静态资源目录路径 func getStaticPath() string { exeDir, _ := os.Getwd() return filepath.Join(exeDir, "..", "static") } // registerStaticRoutes 注册静态资源路由 func registerStaticRoutes(r *gin.Engine) { staticPath := getStaticPath() // 静态资源目录 r.Static("/static", staticPath) }