-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
52 lines (50 loc) · 837 Bytes
/
delete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
func del(labels []label) error {
db, err := openDB()
if err != nil {
return err
}
defer db.close()
info, err := db.del(labels)
if err == nil {
cliPrint(info)
}
return err
}
func (db *db) del(labels []label) ([]label, error) {
m := mapLabels(labels)
info, err := db.get(
[]label{
{Key: "name", Value: m["name"]},
{Key: "type", Value: m["type"]},
{Key: "action", Value: "delete"},
},
)
if err != nil {
return []label{}, err
}
db.Lock()
defer db.Unlock()
switch m["type"] {
case "host":
{
delete(db.hosts, m["name"])
}
case "file":
{
delete(db.files, m["name"])
// db.cleanOrphans()
}
case "group":
{
delete(db.groups, m["name"])
}
case "script":
{
delete(db.scripts, m["name"])
// db.cleanOrphans()
}
}
// log.Println(info[0])
return info[0], err
}