forked from ccfos/nightingale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter_classpath.go
152 lines (113 loc) · 3.1 KB
/
router_classpath.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package http
import (
"time"
"github.com/gin-gonic/gin"
"github.com/didi/nightingale/v5/models"
)
func classpathListGets(c *gin.Context) {
limit := queryInt(c, "limit", defaultLimit)
query := queryStr(c, "query", "")
total, err := models.ClasspathTotal(query)
dangerous(err)
list, err := models.ClasspathGets(query, limit, offset(c, limit))
dangerous(err)
renderData(c, gin.H{
"list": list,
"total": total,
}, nil)
}
//此api暂时不对外开放
func classpathListNodeGets(c *gin.Context) {
query := queryStr(c, "query", "")
list, err := models.ClasspathNodeGets(query)
dangerous(err)
renderData(c, list, nil)
}
func classpathListNodeGetsById(c *gin.Context) {
cp := Classpath(urlParamInt64(c, "id"))
children, err := cp.DirectChildren()
renderData(c, children, err)
}
func classpathFavoriteGet(c *gin.Context) {
lst, err := loginUser(c).FavoriteClasspaths()
renderData(c, lst, err)
}
type classpathForm struct {
Path string `json:"path"`
Note string `json:"note"`
}
func classpathAdd(c *gin.Context) {
var f classpathForm
bind(c, &f)
me := loginUser(c).MustPerm("classpath_create")
cp := models.Classpath{
Path: f.Path,
Note: f.Note,
Preset: 0,
CreateBy: me.Username,
UpdateBy: me.Username,
}
renderMessage(c, cp.Add())
}
func classpathPut(c *gin.Context) {
var f classpathForm
bind(c, &f)
me := loginUser(c).MustPerm("classpath_modify")
cp := Classpath(urlParamInt64(c, "id"))
if cp.Path != f.Path {
num, err := models.ClasspathCount("path=? and id<>?", f.Path, cp.Id)
dangerous(err)
if num > 0 {
bomb(200, "Classpath %s already exists", f.Path)
}
}
cp.Path = f.Path
cp.Note = f.Note
cp.UpdateBy = me.Username
cp.UpdateAt = time.Now().Unix()
renderMessage(c, cp.Update("path", "note", "update_by", "update_at"))
}
func classpathDel(c *gin.Context) {
loginUser(c).MustPerm("classpath_delete")
cp := Classpath(urlParamInt64(c, "id"))
if cp.Preset == 1 {
bomb(200, "Preset classpath %s cannot delete", cp.Path)
}
renderMessage(c, cp.Del())
}
func classpathAddResources(c *gin.Context) {
var arr []string
bind(c, &arr)
me := loginUser(c).MustPerm("classpath_add_resource")
cp := Classpath(urlParamInt64(c, "id"))
dangerous(cp.AddResources(arr))
cp.UpdateAt = time.Now().Unix()
cp.UpdateBy = me.Username
cp.Update("update_at", "update_by")
renderMessage(c, nil)
}
func classpathDelResources(c *gin.Context) {
var arr []string
bind(c, &arr)
classpathId := urlParamInt64(c, "id")
me := loginUser(c).MustPerm("classpath_del_resource")
if classpathId == 1 {
bomb(200, _s("Resource cannot delete in preset classpath"))
}
cp := Classpath(classpathId)
dangerous(cp.DelResources(arr))
cp.UpdateAt = time.Now().Unix()
cp.UpdateBy = me.Username
cp.Update("update_at", "update_by")
renderMessage(c, nil)
}
func classpathFavoriteAdd(c *gin.Context) {
me := loginUser(c)
cp := Classpath(urlParamInt64(c, "id"))
renderMessage(c, models.ClasspathFavoriteAdd(cp.Id, me.Id))
}
func classpathFavoriteDel(c *gin.Context) {
me := loginUser(c)
cp := Classpath(urlParamInt64(c, "id"))
renderMessage(c, models.ClasspathFavoriteDel(cp.Id, me.Id))
}