mc-client-updater-server/internal/api/v1/router.go

46 lines
867 B
Go
Raw Normal View History

2022-10-03 15:07:08 +08:00
package v1
2022-10-04 00:36:01 +08:00
import (
"github.com/gin-gonic/gin"
"mc-client-updater-server/internal/api/v1/handler"
"mc-client-updater-server/internal/api/v1/middleware"
"net/http"
)
2022-10-03 15:07:08 +08:00
func NewRouter() *gin.Engine {
2022-10-04 00:36:01 +08:00
r := gin.New()
r.Use()
r.Use(middleware.LoggerMiddleware())
r.Use(gin.Recovery())
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Hello Minecraft-Client-Updater service!")
})
2022-10-03 15:07:08 +08:00
v1 := r.Group("/api/v1")
v1.GET("/status")
2022-10-04 00:36:01 +08:00
v1.POST("/login", handler.HandleLogin)
2022-10-03 15:07:08 +08:00
/**
GROUP /instance/:name
2022-10-04 00:36:01 +08:00
Grant required
2022-10-03 15:07:08 +08:00
*/
2022-10-04 00:36:01 +08:00
inst := v1.Group("/instance/:name", middleware.GrantRequired)
{
2024-01-07 15:13:35 +08:00
inst.POST("/upload", )
2022-10-04 00:36:01 +08:00
}
2022-10-03 15:07:08 +08:00
/**
GROUP /admin
Auth required
ROLE >= ROLE_admin
*/
2022-10-04 00:36:01 +08:00
admin := v1.Group("/admin", middleware.AdminRequired)
{
2024-01-07 15:13:35 +08:00
admin.POST("/new_instance", handler.HandleNewInstance)
admin.POST("/grant/add", handler.HandleGrantAdd)
2022-10-04 00:36:01 +08:00
}
2022-10-03 15:07:08 +08:00
return r
}