-
Notifications
You must be signed in to change notification settings - Fork 1
/
imp_route.go
64 lines (50 loc) · 1.53 KB
/
imp_route.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
package dao
import (
"database/sql"
"github.com/xfyun/xns/models"
)
type impRoute struct {
*baseDao
}
func NewRouteDao(db *sql.DB)Route{
return &impRoute{baseDao:newBaseDao(db,&models.Route{},ChannelRoute,TableRoute)}
}
func (i *impRoute) GetList() (routes []*models.Route, err error) {
err = i.queryAll(&routes)
return
}
func (i *impRoute) Create(r *models.Route) error {
createBase(&r.Base)
return i.insertAndSendEvent(r,r.Id)
}
func (i *impRoute) Update(id string, srv *models.Route) error {
updateBase(&srv.Base)
return i.updateAndSendEvent(newIdCond(id),srv,id)
}
func (i *impRoute) Delete(id string) error {
return i.deleteAndSendEvent(newIdCond(id),id)
}
func (i *impRoute) Patch(id string, route map[string]interface{}) error {
patchBase(route)
return i.updateAndSendEvent(newIdCond(id),route,id)
}
func (i *impRoute) GetById(id string) (res *models.Route, err error) {
res = &models.Route{}
err = i.queryByCond(newIdCond(id),res)
return
}
func (i *impRoute) GetServiceRoutes(serviceId string) (res []*models.Route, err error) {
err = i.queryByCond(newCond().eq("service_id",serviceId).String(),&res)
return
}
func (i *impRoute)QueryRoutes(host,rule string)(res []*models.Route,err error){
cond := newCond()
cond.queryConds(condKV{key: "domains", val: host, cond: cond.contains},
condKV{key: "rules", val: rule, cond: cond.contains})
err = i.queryByCond(cond.String(),&res)
return
}
func (i *impRoute)QueryRoutesByRuleCond(conds string)(res []*models.Route,err error){
err = i.queryByCond(conds,&res)
return
}