c04cbd73c7a14525a842be18c40c33e6f691f23b
[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         StatusPause       = "Pause"
18         StatusSyncing     = "Syncing"
19 )
20
21 type EventCBData map[string]interface{}
22 type EventCB func(cfg *FolderConfig, data *EventCBData)
23
24 // IFOLDER Folder interface
25 type IFOLDER interface {
26         NewUID(suffix string) string                              // Get a new folder UUID
27         Add(cfg FolderConfig) (*FolderConfig, error)              // Add a new folder
28         GetConfig() FolderConfig                                  // Get folder public configuration
29         GetFullPath(dir string) string                            // Get folder full path
30         Remove() error                                            // Remove a folder
31         RegisterEventChange(cb *EventCB, data *EventCBData) error // Request events registration (sent through WS)
32         UnRegisterEventChange() error                             // Un-register events
33         Sync() error                                              // Force folder files synchronization
34         IsInSync() (bool, error)                                  // Check if folder files are in-sync
35 }
36
37 // FolderConfig is the config for one folder
38 type FolderConfig struct {
39         ID         string     `json:"id"`
40         Label      string     `json:"label"`
41         ClientPath string     `json:"path"`
42         Type       FolderType `json:"type"`
43         Status     string     `json:"status"`
44         IsInSync   bool       `json:"isInSync"`
45         DefaultSdk string     `json:"defaultSdk"`
46
47         // Not exported fields from REST API point of view
48         RootPath string `json:"-"`
49
50         // FIXME: better to define an equivalent to union data and then implement
51         // UnmarshalJSON/MarshalJSON to decode/encode according to Type value
52         // Data interface{} `json:"data"`
53
54         // Specific data depending on which Type is used
55         DataPathMap   PathMapConfig   `json:"dataPathMap,omitempty"`
56         DataCloudSync CloudSyncConfig `json:"dataCloudSync,omitempty"`
57 }
58
59 // PathMapConfig Path mapping specific data
60 type PathMapConfig struct {
61         ServerPath string `json:"serverPath"`
62 }
63
64 // CloudSyncConfig CloudSync (AKA Syncthing) specific data
65 type CloudSyncConfig struct {
66         SyncThingID   string `json:"syncThingID"`
67         BuilderSThgID string `json:"builderSThgID"`
68 }