/
http_client.go
55 lines (47 loc) · 1.15 KB
/
http_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package broker
import (
"github.com/gin-gonic/gin"
restful "github.com/sestack/grf"
"github.com/sestack/smq/model"
)
type clientView struct {
Cluster *Cluster
}
// @Tags 客户端管理
// @Summary 客户端列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} object "{"code": 0, "data": []}"
// @Router /api/v1/client/ [get]
func (self *clientView) List(c *gin.Context) {
datas := []*model.Client{}
clients, err := self.Cluster.GetClients()
if err != nil {
restful.ErrorData(c, err)
return
}
for _, data := range clients {
datas = append(datas, data)
}
restful.SuccessData(c, datas)
return
}
// @Tags 客户端管理
// @Summary 查看客户端
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param id path string true "客户端id"
// @Success 200 {object} object "{"code": 0, "data":{}}"
// @Router /api/v1/client/{id}/ [get]
func (self *clientView) Retrieve(c *gin.Context) {
clientID := c.Param("id")
client, err := self.Cluster.GetClient(clientID)
if err != nil {
restful.NotFound(c)
return
}
restful.SuccessData(c, client)
return
}