-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_source.go
74 lines (66 loc) · 1.71 KB
/
api_source.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
/**********************************************
** @Des: 接口资源
** @Author: yongze.chen
** @Date: 2018-01-14 15:42:43
** @Last Modified by: yongze.chen
** @Last Modified time: 2018-01-14 15:42:43
***********************************************/
package models
import (
"github.com/astaxie/beego/orm"
)
type ApiSource struct {
Id int
GroupId int
SourceName string
Status int
CreateId int
AuditId int
UpdateId int
CreateTime int64
UpdateTime int64
AuditTime int64
}
func (a *ApiSource) TableName() string {
return TableName("api_source")
}
func ApiSourceAdd(a *ApiSource) (int64, error) {
return orm.NewOrm().Insert(a)
}
func ApiSourceGetByName(ApiSourceName string) (*ApiSource, error) {
a := new(ApiSource)
err := orm.NewOrm().QueryTable(TableName("api_source")).Filter("source_name", ApiSourceName).One(a)
if err != nil {
return nil, err
}
return a, nil
}
func ApiSourceGetList(page, pageSize int, filters ...interface{}) ([]*ApiSource, int64) {
offset := (page - 1) * pageSize
list := make([]*ApiSource, 0)
query := orm.NewOrm().QueryTable(TableName("api_source"))
if len(filters) > 0 {
l := len(filters)
for k := 0; k < l; k += 2 {
query = query.Filter(filters[k].(string), filters[k+1])
}
}
total, _ := query.Count()
query.OrderBy("-id").Limit(pageSize, offset).All(&list)
// total := int64(12)
return list, total
}
func ApiSourceGetById(id int) (*ApiSource, error) {
r := new(ApiSource)
err := orm.NewOrm().QueryTable(TableName("api_source")).Filter("id", id).One(r)
if err != nil {
return nil, err
}
return r, nil
}
func (a *ApiSource) Update(fields ...string) error {
if _, err := orm.NewOrm().Update(a, fields...); err != nil {
return err
}
return nil
}