aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/folderconfig.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-11 19:42:00 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-11 19:42:22 +0200
commitec7051e1da665206f594c7616ad381bfeaea333a (patch)
treeecc01ee358794c9d8c5fbb87d2f5b6ce3f60f431 /lib/xdsconfig/folderconfig.go
parentca3e1762832b27dc25cf90125b376c56e24e2db2 (diff)
Initial main commit.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsconfig/folderconfig.go')
-rw-r--r--lib/xdsconfig/folderconfig.go79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/xdsconfig/folderconfig.go b/lib/xdsconfig/folderconfig.go
new file mode 100644
index 0000000..e8bff4f
--- /dev/null
+++ b/lib/xdsconfig/folderconfig.go
@@ -0,0 +1,79 @@
+package xdsconfig
+
+import (
+ "fmt"
+ "log"
+ "path/filepath"
+)
+
+// FolderType constances
+const (
+ FolderTypeDocker = 0
+ FolderTypeWindowsSubsystem = 1
+ FolderTypeCloudSync = 2
+
+ FolderStatusErrorConfig = "ErrorConfig"
+ FolderStatusDisable = "Disable"
+ FolderStatusEnable = "Enable"
+)
+
+// FolderType is the type of sharing folder
+type FolderType int
+
+// FolderConfig is the config for one folder
+type FolderConfig struct {
+ ID string `json:"id" binding:"required"`
+ Label string `json:"label"`
+ RelativePath string `json:"path"`
+ Type FolderType `json:"type"`
+ SyncThingID string `json:"syncThingID"`
+ BuilderSThgID string `json:"builderSThgID"`
+ Status string `json:"status"`
+
+ // Private fields
+ rootPath string
+}
+
+// NewFolderConfig creates a new folder object
+func NewFolderConfig(id, label, rootDir, path string) FolderConfig {
+ return FolderConfig{
+ ID: id,
+ Label: label,
+ RelativePath: path,
+ Type: FolderTypeCloudSync,
+ SyncThingID: "",
+ Status: FolderStatusDisable,
+ rootPath: rootDir,
+ }
+}
+
+// GetFullPath returns the full path
+func (c *FolderConfig) GetFullPath(dir string) string {
+ if &dir == nil {
+ dir = ""
+ }
+ if filepath.IsAbs(dir) {
+ return filepath.Join(c.rootPath, dir)
+ }
+ return filepath.Join(c.rootPath, c.RelativePath, dir)
+}
+
+// FolderVerify is called to verify that a configuration is valid
+func FolderVerify(fCfg FolderConfig) error {
+ var err error
+
+ if fCfg.Type != FolderTypeCloudSync {
+ err = fmt.Errorf("Unsupported folder type")
+ }
+
+ if fCfg.SyncThingID == "" {
+ err = fmt.Errorf("device id not set (SyncThingID field)")
+ }
+
+ if err != nil {
+ fCfg.Status = FolderStatusErrorConfig
+ log.Printf("ERROR FolderVerify: %v\n", err)
+ }
+
+ return err
+}