Add folder update support and ClientData field.
[src/xds/xds-server.git] / lib / folder / folder-pathmap.go
index bc714dd..c5691a3 100644 (file)
@@ -33,7 +33,11 @@ func NewFolderPathMap(gc *xdsconfig.Config) *PathMap {
 
 // NewUID Get a UUID
 func (f *PathMap) NewUID(suffix string) string {
-       return uuid.NewV1().String() + "_" + suffix
+       uuid := uuid.NewV1().String()
+       if len(suffix) > 0 {
+               uuid += "_" + suffix
+       }
+       return uuid
 }
 
 // Add a new folder
@@ -141,6 +145,15 @@ func (f *PathMap) Remove() error {
        return nil
 }
 
+// Update update some fields of a folder
+func (f *PathMap) Update(cfg FolderConfig) (*FolderConfig, error) {
+       if f.config.ID != cfg.ID {
+               return nil, fmt.Errorf("Invalid id")
+       }
+       f.config = cfg
+       return &f.config, nil
+}
+
 // RegisterEventChange requests registration for folder change event
 func (f *PathMap) RegisterEventChange(cb *EventCB, data *EventCBData) error {
        return nil