aboutsummaryrefslogtreecommitdiffstats
path: root/lib/apiv1/apiv1.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-15 11:12:21 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-15 19:08:31 +0200
commitbfeab33538d50ee52750de4dd4c0e72b64f674f6 (patch)
treea8ebab2a62f4ca4ccbfbe848106ca53d708c724b /lib/apiv1/apiv1.go
Initial commit.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/apiv1/apiv1.go')
-rw-r--r--lib/apiv1/apiv1.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/apiv1/apiv1.go b/lib/apiv1/apiv1.go
new file mode 100644
index 0000000..734929b
--- /dev/null
+++ b/lib/apiv1/apiv1.go
@@ -0,0 +1,36 @@
+package apiv1
+
+import (
+ "github.com/Sirupsen/logrus"
+ "github.com/gin-gonic/gin"
+
+ "github.com/iotbzh/xds-agent/lib/session"
+ "github.com/iotbzh/xds-agent/lib/xdsconfig"
+)
+
+// APIService .
+type APIService struct {
+ router *gin.Engine
+ apiRouter *gin.RouterGroup
+ sessions *session.Sessions
+ cfg *xdsconfig.Config
+ log *logrus.Logger
+}
+
+// New creates a new instance of API service
+func New(sess *session.Sessions, conf *xdsconfig.Config, log *logrus.Logger, r *gin.Engine) *APIService {
+ s := &APIService{
+ router: r,
+ sessions: sess,
+ apiRouter: r.Group("/api/v1"),
+ cfg: conf,
+ log: log,
+ }
+
+ s.apiRouter.GET("/version", s.getVersion)
+
+ s.apiRouter.GET("/config", s.getConfig)
+ s.apiRouter.POST("/config", s.setConfig)
+
+ return s
+}