-
Notifications
You must be signed in to change notification settings - Fork 1
/
categorys.go
112 lines (95 loc) · 2.97 KB
/
categorys.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package goidoit
import (
"fmt"
"strconv"
"strings"
)
// GetCat returns the category defined by query for an object given by its object ID
func (a *API) GetCat(objID int, query interface{}) (GenericResponse, error) {
var CustomStruct interface{}
switch query.(type) {
case int:
CustomStruct = struct {
ObjID string `json:"objID"`
CatgID int `json:"catgID"`
}{strconv.Itoa(objID), query.(int)}
case string:
CustomStruct = struct {
ObjID string `json:"objID"`
Category string `json:"category"`
}{strconv.Itoa(objID), query.(string)}
default:
return GenericResponse{}, fmt.Errorf("query should be of type int or string")
}
data, err := a.Request("cmdb.category.read", CustomStruct)
if err != nil {
return GenericResponse{}, err
}
return TypeAssertResult(data)
}
// CreateCat creates a category given by its category ID and the defined content in params for a given object ID
func (a *API) CreateCat(ObjID int, CatgID string, Params interface{}) (GenericResponse, error) {
var CustomStruct interface{}
if strings.Contains(CatgID, "_CUSTOM_") {
CustomStruct = struct {
ObjID int `json:"objID"`
CatgID string `json:"category"`
Data interface{} `json:"data"`
}{ObjID, CatgID, Params}
} else {
CustomStruct = struct {
ObjID int `json:"objID"`
CatgID string `json:"catgID"`
Data interface{} `json:"data"`
}{ObjID, CatgID, Params}
}
data, err := a.Request("cmdb.category.create", CustomStruct)
if err != nil {
return GenericResponse{}, err
}
return TypeAssertResult(data)
}
// UpdateCat updates a category given by its category ID and the defined content in params for a given object ID
func (a *API) UpdateCat(ObjID int, CatgID string, Params interface{}) (GenericResponse, error) {
var CustomStruct interface{}
if strings.Contains(CatgID, "_CUSTOM_") {
CustomStruct = struct {
ObjID int `json:"objID"`
CatgID string `json:"category"`
Data interface{} `json:"data"`
}{ObjID, CatgID, Params}
} else {
CustomStruct = struct {
ObjID int `json:"objID"`
CatgID string `json:"catgID"`
Data interface{} `json:"data"`
}{ObjID, CatgID, Params}
}
data, err := a.Request("cmdb.category.update", CustomStruct)
if err != nil {
return GenericResponse{}, err
}
return TypeAssertResult(data)
}
// DelCatObj deletes a given category for a given object
func (a *API) DelCatObj(ObjID int, CatgID string, CateID string) (GenericResponse, error) {
var CustomStruct interface{}
if strings.Contains(CatgID, "_CUSTOM_") {
CustomStruct = struct {
ObjID int `json:"objID"`
CatgID string `json:"category"`
CateID string `json:"id"`
}{ObjID, CatgID, CateID}
} else {
CustomStruct = struct {
ObjID int `json:"objID"`
CatgID string `json:"catgID"`
CateID string `json:"id"`
}{ObjID, CatgID, CateID}
}
data, err := a.Request("cmdb.category.delete", CustomStruct)
if err != nil {
return GenericResponse{}, err
}
return TypeAssertResult(data)
}