mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-22 08:18:29 +02:00
refactor(api): restructured API for type safety, maintainability and docs generation
- 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
This commit is contained in:
41
internal/api/v1/route/route.go
Normal file
41
internal/api/v1/route/route.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user