37 lines
789 B
Go
37 lines
789 B
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// AgentsGroup — группа хэндлеров для агентов
|
|
type AgentsGroup struct {
|
|
*Handlers
|
|
}
|
|
|
|
// List GET /api/v1/agents
|
|
func (ag *AgentsGroup) List(c *gin.Context) {
|
|
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})
|
|
}
|