7 "github.com/gin-gonic/gin"
8 "github.com/iotbzh/xds-server/lib/common"
9 "github.com/iotbzh/xds-server/lib/xdsconfig"
12 // getFolders returns all folders configuration
13 func (s *APIService) getFolders(c *gin.Context) {
15 defer confMut.Unlock()
17 c.JSON(http.StatusOK, s.cfg.Folders)
20 // getFolder returns a specific folder configuration
21 func (s *APIService) getFolder(c *gin.Context) {
22 id, err := strconv.Atoi(c.Param("id"))
23 if err != nil || id < 0 || id > len(s.cfg.Folders) {
24 common.APIError(c, "Invalid id")
29 defer confMut.Unlock()
31 c.JSON(http.StatusOK, s.cfg.Folders[id])
34 // addFolder adds a new folder to server config
35 func (s *APIService) addFolder(c *gin.Context) {
36 var cfgArg xdsconfig.FolderConfig
37 if c.BindJSON(&cfgArg) != nil {
38 common.APIError(c, "Invalid arguments")
43 defer confMut.Unlock()
45 s.log.Debugln("Add folder config: ", cfgArg)
47 newFld, err := s.mfolder.UpdateFolder(cfgArg)
49 common.APIError(c, err.Error())
53 c.JSON(http.StatusOK, newFld)
56 // delFolder deletes folder from server config
57 func (s *APIService) delFolder(c *gin.Context) {
60 common.APIError(c, "Invalid id")
65 defer confMut.Unlock()
67 s.log.Debugln("Delete folder id ", id)
69 var delEntry xdsconfig.FolderConfig
71 if delEntry, err = s.mfolder.DeleteFolder(id); err != nil {
72 common.APIError(c, err.Error())
75 c.JSON(http.StatusOK, delEntry)