9 // FolderType constances
12 FolderTypeWindowsSubsystem = 1
13 FolderTypeCloudSync = 2
15 FolderStatusErrorConfig = "ErrorConfig"
16 FolderStatusDisable = "Disable"
17 FolderStatusEnable = "Enable"
20 // FolderType is the type of sharing folder
23 // FolderConfig is the config for one folder
24 type FolderConfig struct {
25 ID string `json:"id" binding:"required"`
26 Label string `json:"label"`
27 RelativePath string `json:"path"`
28 Type FolderType `json:"type"`
29 SyncThingID string `json:"syncThingID"`
30 BuilderSThgID string `json:"builderSThgID"`
31 Status string `json:"status"`
32 DefaultSdk string `json:"defaultSdk"`
34 // Not exported fields
35 RootPath string `json:"-"`
38 // NewFolderConfig creates a new folder object
39 func NewFolderConfig(id, label, rootDir, path string, defaultSdk string) FolderConfig {
44 Type: FolderTypeCloudSync,
46 Status: FolderStatusDisable,
48 DefaultSdk: defaultSdk,
52 // GetFullPath returns the full path
53 func (c *FolderConfig) GetFullPath(dir string) string {
57 if filepath.IsAbs(dir) {
58 return filepath.Join(c.RootPath, dir)
60 return filepath.Join(c.RootPath, c.RelativePath, dir)
63 // Verify is called to verify that a configuration is valid
64 func (c *FolderConfig) Verify() error {
67 if c.Type != FolderTypeCloudSync {
68 err = fmt.Errorf("Unsupported folder type")
71 if c.SyncThingID == "" {
72 err = fmt.Errorf("device id not set (SyncThingID field)")
76 err = fmt.Errorf("RootPath must not be empty")
80 c.Status = FolderStatusErrorConfig
81 log.Printf("ERROR Verify: %v\n", err)