mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
Moved non-agent-specific logic from agent/pkg/agent/ to internal/agentpool/: - pool.go: Agent pool management (Get, Add, Remove, List, Iter, etc.) - http_requests.go: HTTP utilities (health checks, forwarding, websockets, reverse proxy) - agent.go: Agent struct with HTTP client management This separates general-purpose pool management from agent-specific configuration, improving code organization and making the agent package focused on agent config only.
34 lines
775 B
Go
34 lines
775 B
Go
package agentapi
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/yusing/godoxy/internal/agentpool"
|
|
"github.com/yusing/goutils/http/httpheaders"
|
|
"github.com/yusing/goutils/http/websocket"
|
|
|
|
_ "github.com/yusing/goutils/apitypes"
|
|
)
|
|
|
|
// @x-id "list"
|
|
// @BasePath /api/v1
|
|
// @Summary List agents
|
|
// @Description List agents
|
|
// @Tags agent,websocket
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} agent.AgentConfig
|
|
// @Failure 403 {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 agentpool.List(), nil
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusOK, agentpool.List())
|
|
}
|
|
}
|