mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-17 23:03:49 +01:00
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package routeApi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
apitypes "github.com/yusing/godoxy/internal/api/types"
|
|
statequery "github.com/yusing/godoxy/internal/config/query"
|
|
"github.com/yusing/godoxy/internal/route/routes"
|
|
)
|
|
|
|
type ListRouteRequest struct {
|
|
Which string `uri:"which" validate:"required"`
|
|
} // @name ListRouteRequest
|
|
|
|
// @x-id "route"
|
|
// @BasePath /api/v1
|
|
// @Summary List route
|
|
// @Description List route
|
|
// @Tags route
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param which path string true "Route name"
|
|
// @Success 200 {object} RouteType
|
|
// @Failure 400 {object} apitypes.ErrorResponse
|
|
// @Failure 403 {object} apitypes.ErrorResponse
|
|
// @Failure 404 {object} apitypes.ErrorResponse
|
|
// @Router /route/{which} [get]
|
|
func Route(c *gin.Context) {
|
|
var request ListRouteRequest
|
|
if err := c.ShouldBindUri(&request); err != nil {
|
|
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
|
return
|
|
}
|
|
|
|
route, ok := routes.Get(request.Which)
|
|
if ok {
|
|
c.JSON(http.StatusOK, route)
|
|
return
|
|
}
|
|
|
|
// also search for excluded routes
|
|
route = statequery.SearchRoute(request.Which)
|
|
if route != nil {
|
|
c.JSON(http.StatusOK, route)
|
|
return
|
|
}
|
|
c.JSON(http.StatusNotFound, nil)
|
|
}
|