mirror of
https://git.fightbot.fun/hxuanyu/BingPaper.git
synced 2026-02-15 08:49:33 +08:00
基本功能实现
This commit is contained in:
63
internal/http/router.go
Normal file
63
internal/http/router.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
_ "BingDailyImage/docs"
|
||||
"BingDailyImage/internal/http/handlers"
|
||||
"BingDailyImage/internal/http/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
)
|
||||
|
||||
func SetupRouter() *gin.Engine {
|
||||
r := gin.Default()
|
||||
|
||||
// Swagger
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
// 静态文件
|
||||
r.Static("/static", "./static")
|
||||
r.StaticFile("/", "./web/index.html")
|
||||
r.StaticFile("/admin", "./web/index.html")
|
||||
r.StaticFile("/login", "./web/index.html")
|
||||
|
||||
api := r.Group("/api/v1")
|
||||
{
|
||||
// 公共接口
|
||||
img := api.Group("/image")
|
||||
{
|
||||
img.GET("/today", handlers.GetToday)
|
||||
img.GET("/today/meta", handlers.GetTodayMeta)
|
||||
img.GET("/random", handlers.GetRandom)
|
||||
img.GET("/random/meta", handlers.GetRandomMeta)
|
||||
img.GET("/date/:date", handlers.GetByDate)
|
||||
img.GET("/date/:date/meta", handlers.GetByDateMeta)
|
||||
}
|
||||
api.GET("/images", handlers.ListImages)
|
||||
|
||||
// 管理接口
|
||||
admin := api.Group("/admin")
|
||||
{
|
||||
admin.POST("/login", handlers.AdminLogin)
|
||||
|
||||
// 需要验证的接口
|
||||
authorized := admin.Group("/")
|
||||
authorized.Use(middleware.AuthMiddleware())
|
||||
{
|
||||
authorized.GET("/tokens", handlers.ListTokens)
|
||||
authorized.POST("/tokens", handlers.CreateToken)
|
||||
authorized.PATCH("/tokens/:id", handlers.UpdateToken)
|
||||
authorized.DELETE("/tokens/:id", handlers.DeleteToken)
|
||||
|
||||
authorized.GET("/config", handlers.GetConfig)
|
||||
authorized.PUT("/config", handlers.UpdateConfig)
|
||||
|
||||
authorized.POST("/fetch", handlers.ManualFetch)
|
||||
authorized.POST("/cleanup", handlers.ManualCleanup)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
Reference in New Issue
Block a user