Files
dypid/api/api.go
YGXB_net 819a2eb8ec
All checks were successful
部署开发环境 / deploy-dev (push) Successful in 8m30s
refactor: 重构项目结构并优化路由组织
2025-10-28 12:20:16 +08:00

42 lines
1.2 KiB
Go

package api
import (
"dypid/internal/controller"
"embed"
"io/fs"
"net/http"
"github.com/gin-gonic/gin"
)
func RegRoutes(r *gin.Engine) {
g := r.Group("/api") //初始化路由组 /api/xxxx
{
g.GET("/token", controller.ListTokenHandler) //获取token列表
g.POST("/token", controller.CreateTokenHandler) //创建token
g.PUT("/token", controller.UpdateTokenHandler) //更新token
g.DELETE("/token", controller.DeleteTokenHandler) //删除token
g.GET("/token/info", controller.GetTokenInfoHandler) //获取token信息
g.DELETE("/token/info", controller.DeleteTokenInfoHandler) //删除token数据库
}
{
g.GET("/data", controller.ReadDataHandler) //获取数据
g.POST("/data", controller.WriteDataHandler) //写入数据
}
}
func RegWebService(r *gin.Engine, webDir embed.FS) {
assets, _ := fs.Sub(webDir, "web/dist/assets")
r.StaticFS("/assets", http.FS(assets))
icon, _ := fs.ReadFile(webDir, "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")
r.NoRoute(func(c *gin.Context) {
c.Data(200, "text/html; charset=utf-8", indexHtml)
})
}