0a9631179706655f1fc9d116bf0d8cd99d099280
[src/xds/xds-server.git] / lib / apiv1 / apiv1.go
1 package apiv1
2
3 import (
4         "github.com/Sirupsen/logrus"
5         "github.com/gin-gonic/gin"
6
7         "github.com/iotbzh/xds-server/lib/crosssdk"
8         "github.com/iotbzh/xds-server/lib/model"
9         "github.com/iotbzh/xds-server/lib/session"
10         "github.com/iotbzh/xds-server/lib/xdsconfig"
11 )
12
13 // APIService .
14 type APIService struct {
15         router    *gin.Engine
16         apiRouter *gin.RouterGroup
17         sessions  *session.Sessions
18         cfg       *xdsconfig.Config
19         mfolders  *model.Folders
20         sdks      *crosssdk.SDKs
21         log       *logrus.Logger
22 }
23
24 // New creates a new instance of API service
25 func New(r *gin.Engine, sess *session.Sessions, cfg *xdsconfig.Config, mfolders *model.Folders, sdks *crosssdk.SDKs) *APIService {
26         s := &APIService{
27                 router:    r,
28                 sessions:  sess,
29                 apiRouter: r.Group("/api/v1"),
30                 cfg:       cfg,
31                 mfolders:  mfolders,
32                 sdks:      sdks,
33                 log:       cfg.Log,
34         }
35
36         s.apiRouter.GET("/version", s.getVersion)
37
38         s.apiRouter.GET("/config", s.getConfig)
39         s.apiRouter.POST("/config", s.setConfig)
40
41         s.apiRouter.GET("/folders", s.getFolders)
42         s.apiRouter.GET("/folder/:id", s.getFolder)
43         s.apiRouter.POST("/folder", s.addFolder)
44         s.apiRouter.POST("/folder/sync/:id", s.syncFolder)
45         s.apiRouter.DELETE("/folder/:id", s.delFolder)
46
47         s.apiRouter.GET("/sdks", s.getSdks)
48         s.apiRouter.GET("/sdk/:id", s.getSdk)
49
50         s.apiRouter.POST("/make", s.buildMake)
51         s.apiRouter.POST("/make/:id", s.buildMake)
52
53         s.apiRouter.POST("/exec", s.execCmd)
54         s.apiRouter.POST("/exec/:id", s.execCmd)
55         s.apiRouter.POST("/signal", s.execSignalCmd)
56
57         s.apiRouter.GET("/events", s.eventsList)
58         s.apiRouter.POST("/events/register", s.eventsRegister)
59         s.apiRouter.POST("/events/unregister", s.eventsUnRegister)
60
61         return s
62 }