mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-26 19:11:08 +01:00
- These changes makes the API incombatible with previous versions - Added new types for error handling, success responses, and health checks. - Updated health check logic to utilize the new types for better clarity and structure. - Refactored existing handlers to improve response consistency and error handling. - Updated Makefile to include a new target for generating API types from Swagger. - Updated "new agent" API to respond an encrypted cert pair
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package routeApi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
apitypes "github.com/yusing/go-proxy/internal/api/types"
|
|
"github.com/yusing/go-proxy/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)
|
|
} else {
|
|
c.JSON(http.StatusNotFound, nil)
|
|
}
|
|
}
|