forked from GoAdminGroup/go-admin
-
Notifications
You must be signed in to change notification settings - Fork 21
/
permission.go
52 lines (43 loc) · 1.14 KB
/
permission.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 models
import (
"github.com/chenhg5/go-admin/modules/db"
"strconv"
"strings"
)
type PermissionModel struct {
Base
Id int64
Name string
Slug string
HttpMethod []string
HttpPath []string
CreatedAt string
UpdatedAt string
}
func Permission() PermissionModel {
return PermissionModel{Base: Base{Table: "goadmin_permissions"}}
}
func PermissionWithId(id string) PermissionModel {
idInt, _ := strconv.Atoi(id)
return PermissionModel{Base: Base{Table: "goadmin_permissions"}, Id: int64(idInt)}
}
func (t PermissionModel) Find(id interface{}) PermissionModel {
item, _ := db.Table(t.Table).Find(id)
return t.MapToModel(item)
}
func (t PermissionModel) MapToModel(m map[string]interface{}) PermissionModel {
t.Id = m["id"].(int64)
t.Name, _ = m["name"].(string)
t.Slug, _ = m["slug"].(string)
methods, _ := m["http_method"].(string)
if methods != "" {
t.HttpMethod = strings.Split(methods, ",")
} else {
t.HttpMethod = []string{""}
}
path, _ := m["http_path"].(string)
t.HttpPath = strings.Split(path, "\n")
t.CreatedAt, _ = m["created_at"].(string)
t.UpdatedAt, _ = m["updated_at"].(string)
return t
}