/
model.go
56 lines (45 loc) · 1.03 KB
/
model.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
package controllers
import (
"encoding/json"
"github.com/casbin/casbin-hub/object"
)
func (c *ApiController) GetModels() {
c.Data["json"] = object.GetModels()
c.ServeJSON()
}
func (c *ApiController) GetEmptyModel() {
c.Data["json"] = object.NewModel()
c.ServeJSON()
}
func (c *ApiController) GetModel() {
id := c.Input().Get("id")
c.Data["json"] = object.GetModel(id)
c.ServeJSON()
}
func (c *ApiController) UpdateModels() {
var models []*object.Model
err := json.Unmarshal(c.Ctx.Input.RequestBody, &models)
if err != nil {
panic(err)
}
c.Data["json"] = object.UpdateModels(models)
c.ServeJSON()
}
func (c *ApiController) UpdateModel() {
var model *object.Model
err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
panic(err)
}
c.Data["json"] = object.UpdateModel(model)
c.ServeJSON()
}
func (c *ApiController) DeleteModel() {
var model *object.Model
err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
panic(err)
}
c.Data["json"] = object.DeleteModel(model)
c.ServeJSON()
}