This commit is contained in:
41
api/api.go
Normal file
41
api/api.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user