6 "github.com/gin-gonic/gin"
7 "github.com/iotbzh/xds-agent/lib/xaapiv1"
8 common "github.com/iotbzh/xds-common/golib"
11 // eventsList Registering for events that will be send over a WS
12 func (s *APIService) eventsList(c *gin.Context) {
13 c.JSON(http.StatusOK, s.events.GetList())
16 // eventsRegister Registering for events that will be send over a WS
17 func (s *APIService) eventsRegister(c *gin.Context) {
18 var args xaapiv1.EventRegisterArgs
20 if c.BindJSON(&args) != nil || args.Name == "" {
21 common.APIError(c, "Invalid arguments")
25 sess := s.webServer.sessions.Get(c)
27 common.APIError(c, "Unknown sessions")
31 // Register to all or to a specific events
32 if err := s.events.Register(args.Name, sess.ID); err != nil {
33 common.APIError(c, err.Error())
37 c.JSON(http.StatusOK, gin.H{"status": "OK"})
40 // eventsRegister Registering for events that will be send over a WS
41 func (s *APIService) eventsUnRegister(c *gin.Context) {
42 var args xaapiv1.EventUnRegisterArgs
44 if c.BindJSON(&args) != nil || args.Name == "" {
45 common.APIError(c, "Invalid arguments")
49 sess := s.webServer.sessions.Get(c)
51 common.APIError(c, "Unknown sessions")
55 // Register to all or to a specific events
56 if err := s.events.UnRegister(args.Name, sess.ID); err != nil {
57 common.APIError(c, err.Error())
61 c.JSON(http.StatusOK, gin.H{"status": "OK"})