/
widget.go
90 lines (76 loc) Β· 2.07 KB
/
widget.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
package model
type Widget struct {
Chart *Chart `json:"chart,omitempty"`
ChartGroup *ChartGroup `json:"chart_group,omitempty"`
Table *Table `json:"table,omitempty"`
DependencyMap *DependencyMap `json:"dependency_map,omitempty"`
Heatmap *Heatmap `json:"heatmap,omitempty"`
Logs *Logs `json:"logs,omitempty"`
Profiling *Profiling `json:"profiling,omitempty"`
Tracing *Tracing `json:"tracing,omitempty"`
Width string `json:"width,omitempty"`
DocLink *DocLink `json:"doc_link,omitempty"`
}
func (w *Widget) AddAnnotation(annotations ...Annotation) {
if w.Chart != nil {
w.Chart.AddAnnotation(annotations...)
}
if w.ChartGroup != nil {
for _, ch := range w.ChartGroup.Charts {
ch.AddAnnotation(annotations...)
}
}
if w.Heatmap != nil {
w.Heatmap.AddAnnotation(annotations...)
}
}
type DocLink struct {
Group string `json:"group"`
Item string `json:"item"`
Hash string `json:"hash"`
}
func NewDocLink(group, item, hash string) *DocLink {
return &DocLink{
Group: group,
Item: item,
Hash: hash,
}
}
type RouterLink struct {
Title string `json:"title"`
Route string `json:"name,omitempty"`
Params map[string]any `json:"params,omitempty"`
Args map[string]any `json:"query,omitempty"`
Hash string `json:"hash,omitempty"`
}
func NewRouterLink(title string, route string) *RouterLink {
return &RouterLink{Title: title, Route: route}
}
func (l *RouterLink) SetParam(k string, v any) *RouterLink {
if l.Params == nil {
l.Params = map[string]any{}
}
l.Params[k] = v
return l
}
func (l *RouterLink) SetArg(k string, v any) *RouterLink {
if l.Args == nil {
l.Args = map[string]any{}
}
l.Args[k] = v
return l
}
func (l *RouterLink) SetHash(v string) *RouterLink {
l.Hash = "#" + v
return l
}
type Logs struct {
ApplicationId ApplicationId `json:"application_id"`
Check *Check `json:"check"`
}
type Profiling struct {
ApplicationId ApplicationId `json:"application_id"`
}
type Tracing struct {
ApplicationId ApplicationId `json:"application_id"`
}