mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 15:34:38 +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
33 lines
806 B
Go
33 lines
806 B
Go
package agentapi
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/yusing/go-proxy/agent/pkg/agent"
|
|
"github.com/yusing/go-proxy/internal/net/gphttp/httpheaders"
|
|
"github.com/yusing/go-proxy/internal/net/gphttp/websocket"
|
|
)
|
|
|
|
// @x-id "list"
|
|
// @BasePath /api/v1
|
|
// @Summary List agents
|
|
// @Description List agents
|
|
// @Tags agent,websocket
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} Agent
|
|
// @Failure 403 {object} apitypes.ErrorResponse
|
|
// @Failure 500 {object} apitypes.ErrorResponse
|
|
// @Router /agent/list [get]
|
|
func List(c *gin.Context) {
|
|
if httpheaders.IsWebsocket(c.Request.Header) {
|
|
websocket.PeriodicWrite(c, 10*time.Second, func() (any, error) {
|
|
return agent.ListAgents(), nil
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusOK, agent.ListAgents())
|
|
}
|
|
}
|