aboutsummaryrefslogtreecommitdiffstats
path: root/lib/apiv1/folders.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-10 12:19:34 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-16 14:27:28 +0200
commitdd6f08b10b1597f44e3dc25509ac9a45336b0914 (patch)
tree3dcb835306bc3adbae7c27d94fc8a51de8d6f09a /lib/apiv1/folders.go
parent0262f5bef6ff67e77b844a04733c57740fba9f00 (diff)
Add folder interface and support native pathmap folder type.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/apiv1/folders.go')
-rw-r--r--lib/apiv1/folders.go36
1 files changed, 9 insertions, 27 deletions
diff --git a/lib/apiv1/folders.go b/lib/apiv1/folders.go
index 44bda24..f957c6d 100644
--- a/lib/apiv1/folders.go
+++ b/lib/apiv1/folders.go
@@ -2,49 +2,39 @@ package apiv1
import (
"net/http"
- "strconv"
"github.com/gin-gonic/gin"
common "github.com/iotbzh/xds-common/golib"
- "github.com/iotbzh/xds-server/lib/xdsconfig"
+ "github.com/iotbzh/xds-server/lib/folder"
)
// getFolders returns all folders configuration
func (s *APIService) getFolders(c *gin.Context) {
- confMut.Lock()
- defer confMut.Unlock()
-
- c.JSON(http.StatusOK, s.cfg.Folders)
+ c.JSON(http.StatusOK, s.mfolders.GetConfigArr())
}
// getFolder returns a specific folder configuration
func (s *APIService) getFolder(c *gin.Context) {
- id, err := strconv.Atoi(c.Param("id"))
- if err != nil || id < 0 || id > len(s.cfg.Folders) {
+ f := s.mfolders.Get(c.Param("id"))
+ if f == nil {
common.APIError(c, "Invalid id")
return
}
- confMut.Lock()
- defer confMut.Unlock()
-
- c.JSON(http.StatusOK, s.cfg.Folders[id])
+ c.JSON(http.StatusOK, (*f).GetConfig())
}
// addFolder adds a new folder to server config
func (s *APIService) addFolder(c *gin.Context) {
- var cfgArg xdsconfig.FolderConfig
+ var cfgArg folder.FolderConfig
if c.BindJSON(&cfgArg) != nil {
common.APIError(c, "Invalid arguments")
return
}
- confMut.Lock()
- defer confMut.Unlock()
-
s.log.Debugln("Add folder config: ", cfgArg)
- newFld, err := s.mfolder.UpdateFolder(cfgArg)
+ newFld, err := s.mfolders.Add(cfgArg)
if err != nil {
common.APIError(c, err.Error())
return
@@ -56,19 +46,11 @@ func (s *APIService) addFolder(c *gin.Context) {
// delFolder deletes folder from server config
func (s *APIService) delFolder(c *gin.Context) {
id := c.Param("id")
- if id == "" {
- common.APIError(c, "Invalid id")
- return
- }
-
- confMut.Lock()
- defer confMut.Unlock()
s.log.Debugln("Delete folder id ", id)
- var delEntry xdsconfig.FolderConfig
- var err error
- if delEntry, err = s.mfolder.DeleteFolder(id); err != nil {
+ delEntry, err := s.mfolders.Delete(id)
+ if err != nil {
common.APIError(c, err.Error())
return
}