Add folder interface and support native pathmap folder type.
[src/xds/xds-server.git] / lib / folder / folder-interface.go
1 package folder
2
3 // FolderType definition
4 type FolderType int
5
6 const (
7         TypePathMap   = 1
8         TypeCloudSync = 2
9         TypeCifsSmb   = 3
10 )
11
12 // Folder Status definition
13 const (
14         StatusErrorConfig = "ErrorConfig"
15         StatusDisable     = "Disable"
16         StatusEnable      = "Enable"
17 )
18
19 // IFOLDER Folder interface
20 type IFOLDER interface {
21         Add(cfg FolderConfig) (*FolderConfig, error) // Add a new folder
22         GetConfig() FolderConfig                     // Get folder public configuration
23         GetFullPath(dir string) string               // Get folder full path
24         Remove() error                               // Remove a folder
25         Sync() error                                 // Force folder files synchronization
26         IsInSync() (bool, error)                     // Check if folder files are in-sync
27 }
28
29 // FolderConfig is the config for one folder
30 type FolderConfig struct {
31         ID         string     `json:"id"`
32         Label      string     `json:"label"`
33         ClientPath string     `json:"path"`
34         Type       FolderType `json:"type"`
35         Status     string     `json:"status"`
36         DefaultSdk string     `json:"defaultSdk"`
37
38         // Not exported fields from REST API point of view
39         RootPath string `json:"-"`
40
41         // FIXME: better to define an equivalent to union data and then implement
42         // UnmarshalJSON/MarshalJSON to decode/encode according to Type value
43         // Data interface{} `json:"data"`
44
45         // Specific data depending on which Type is used
46         DataPathMap   PathMapConfig   `json:"dataPathMap,omitempty"`
47         DataCloudSync CloudSyncConfig `json:"dataCloudSync,omitempty"`
48 }
49
50 // PathMapConfig Path mapping specific data
51 type PathMapConfig struct {
52         ServerPath string `json:"serverPath"`
53 }
54
55 // CloudSyncConfig CloudSync (AKA Syncthing) specific data
56 type CloudSyncConfig struct {
57         SyncThingID   string `json:"syncThingID"`
58         BuilderSThgID string `json:"builderSThgID"`
59 }