This commit is contained in:
@@ -50,8 +50,6 @@ func main() {
|
|||||||
agentsGroup := v1.Group("/agents")
|
agentsGroup := v1.Group("/agents")
|
||||||
{
|
{
|
||||||
agentsGroup.GET("", agents.List)
|
agentsGroup.GET("", agents.List)
|
||||||
agentsGroup.GET("/:id", agents.GetByID)
|
|
||||||
agentsGroup.POST("", agents.Create)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+44
-1
@@ -14,7 +14,50 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {},
|
"paths": {
|
||||||
|
"/agents": {
|
||||||
|
"get": {
|
||||||
|
"description": "Returns a list of all agents currently connected via gRPC streaming",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"agents"
|
||||||
|
],
|
||||||
|
"summary": "Get connected agents",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/internal_handlers.AgentInfo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"internal_handlers.AgentInfo": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"services": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"token": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
"Bearer": {
|
"Bearer": {
|
||||||
"description": "Type \"Bearer\" followed by a space and the JWT token.",
|
"description": "Type \"Bearer\" followed by a space and the JWT token.",
|
||||||
|
|||||||
@@ -3,7 +3,50 @@
|
|||||||
"info": {
|
"info": {
|
||||||
"contact": {}
|
"contact": {}
|
||||||
},
|
},
|
||||||
"paths": {},
|
"paths": {
|
||||||
|
"/agents": {
|
||||||
|
"get": {
|
||||||
|
"description": "Returns a list of all agents currently connected via gRPC streaming",
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"agents"
|
||||||
|
],
|
||||||
|
"summary": "Get connected agents",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OK",
|
||||||
|
"schema": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/internal_handlers.AgentInfo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"internal_handlers.AgentInfo": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"label": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"services": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"token": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
"Bearer": {
|
"Bearer": {
|
||||||
"description": "Type \"Bearer\" followed by a space and the JWT token.",
|
"description": "Type \"Bearer\" followed by a space and the JWT token.",
|
||||||
|
|||||||
@@ -1,6 +1,33 @@
|
|||||||
|
definitions:
|
||||||
|
internal_handlers.AgentInfo:
|
||||||
|
properties:
|
||||||
|
label:
|
||||||
|
type: string
|
||||||
|
services:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
token:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
paths: {}
|
paths:
|
||||||
|
/agents:
|
||||||
|
get:
|
||||||
|
description: Returns a list of all agents currently connected via gRPC streaming
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/internal_handlers.AgentInfo'
|
||||||
|
type: array
|
||||||
|
summary: Get connected agents
|
||||||
|
tags:
|
||||||
|
- agents
|
||||||
securityDefinitions:
|
securityDefinitions:
|
||||||
Bearer:
|
Bearer:
|
||||||
description: Type "Bearer" followed by a space and the JWT token.
|
description: Type "Bearer" followed by a space and the JWT token.
|
||||||
|
|||||||
@@ -1,36 +1,26 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AgentsGroup — группа хэндлеров для агентов
|
|
||||||
type AgentsGroup struct {
|
type AgentsGroup struct {
|
||||||
*Handlers
|
*Handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
// List GET /api/v1/agents
|
type AgentInfo struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
Label string `json:"label"`
|
||||||
|
Services []string `json:"services"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Summary Get connected agents
|
||||||
|
// @Description Returns a list of all agents currently connected via gRPC streaming
|
||||||
|
// @Tags agents
|
||||||
|
// @Produce json
|
||||||
|
// @Success 200 {array} AgentInfo
|
||||||
|
// @Router /agents [get]
|
||||||
func (ag *AgentsGroup) List(c *gin.Context) {
|
func (ag *AgentsGroup) List(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, gin.H{"message": "Agents list"})
|
c.JSON(http.StatusOK, gin.H{"message": "Agents list"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByID GET /api/v1/agents/:id
|
|
||||||
func (ag *AgentsGroup) GetByID(c *gin.Context) {
|
|
||||||
id := c.Param("id")
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"id": id})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create POST /api/v1/agents
|
|
||||||
func (ag *AgentsGroup) Create(c *gin.Context) {
|
|
||||||
var body struct {
|
|
||||||
Name string `json:"name" binding:"required"`
|
|
||||||
}
|
|
||||||
if err := c.ShouldBindJSON(&body); err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.JSON(http.StatusCreated, gin.H{"name": body.Name})
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user