-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctx.go
49 lines (40 loc) · 1.01 KB
/
ctx.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
package res
import (
"log"
"github.com/eynstudio/gobreak"
"github.com/eynstudio/gobreak/orm"
"github.com/eynstudio/gox/utils"
)
var Ctx = &ResCtx{}
type ResCtx struct {
}
func (p *ResCtx) orm() *orm.Orm { return orm.GetOrmByName("auth") }
func (p *ResCtx) Get(id gobreak.GUID) (m AuthRes, ok bool) {
ok = p.orm().WhereId(id).GetJson2(&m)
return
}
func (p *ResCtx) All() (lst []AuthRes, err error) {
err = p.orm().AllJson(&lst)
return
}
func (p *ResCtx) AllAsTree() (tree utils.TreeNodes, err error) {
var lst []AuthRes
if err = p.orm().AllJson(&lst); err != nil {
return nil, err
}
return utils.BuildTree(lst), nil
}
func (p *ResCtx) Save(m *AuthRes) gobreak.IStatus {
err := p.orm().SaveJson(m.Id, m)
if err != nil {
log.Println(err)
}
return gobreak.NewStatusErr(err, "保存成功", "保存失败")
}
func (p *ResCtx) Del(id gobreak.GUID) gobreak.IStatus {
err := p.orm().DelId(&AuthRes{}, id)
if err != nil {
log.Println(err)
}
return gobreak.NewStatusErr(err, "保存成功", "保存失败")
}