ExecuteDelete removes the configured entry from the main configuration.
()
| 15 | |
| 16 | // ExecuteDelete removes the configured entry from the main configuration. |
| 17 | func (dc *DeleteController) ExecuteDelete() { |
| 18 | switch dc.deleteType { |
| 19 | case TypeUsers: |
| 20 | if newContents := dc.searchAndDelete(dc.configuration.Main.Users); newContents != nil { |
| 21 | dc.configuration.Main.Users = newContents |
| 22 | dc.updateConfig() |
| 23 | } else { |
| 24 | utils.Warnf("No matching username: %s\n", dc.deleteContent) |
| 25 | } |
| 26 | case TypePorts: |
| 27 | if newContents := dc.searchAndDelete(dc.configuration.Main.Ports); newContents != nil { |
| 28 | dc.configuration.Main.Ports = newContents |
| 29 | dc.updateConfig() |
| 30 | } else { |
| 31 | utils.Warnf("No matching port: %s\n", dc.deleteContent) |
| 32 | } |
| 33 | case TypePasswords: |
| 34 | if newContents := dc.searchAndDelete(dc.configuration.Main.Passwords); newContents != nil { |
| 35 | dc.configuration.Main.Passwords = newContents |
| 36 | dc.updateConfig() |
| 37 | } else { |
| 38 | utils.Warnln("No matching password") |
| 39 | } |
| 40 | case TypeKeys: |
| 41 | if newContents := dc.searchAndDelete(dc.configuration.Main.Keys); newContents != nil { |
| 42 | dc.configuration.Main.Keys = newContents |
| 43 | dc.updateConfig() |
| 44 | } else { |
| 45 | utils.Warnf("No matching key: %s\n", dc.deleteContent) |
| 46 | } |
| 47 | case TypeCaches: |
| 48 | if dc.deleteContent == "" { |
| 49 | utils.Errorln("IP address cannot be empty characters") |
| 50 | return |
| 51 | } |
| 52 | var deleteCount int |
| 53 | for i := len(dc.configuration.ServerLists) - 1; i >= 0; i-- { |
| 54 | if dc.configuration.ServerLists[i].IP == dc.deleteContent { |
| 55 | dc.configuration.ServerLists = append(dc.configuration.ServerLists[:i], |
| 56 | dc.configuration.ServerLists[i+1:]...) |
| 57 | deleteCount++ |
| 58 | } |
| 59 | } |
| 60 | if deleteCount > 0 { |
| 61 | dc.updateConfig() |
| 62 | } else { |
| 63 | utils.Warnf("No matching cache: %s\n", dc.deleteContent) |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func (dc *DeleteController) searchAndDelete(contents []string) []string { |
| 69 | for index, content := range contents { |