/
proxy.go
65 lines (55 loc) · 1.32 KB
/
proxy.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
package models
import "fmt"
const (
MODE_LOCAL = "local"
MODE_REMOTE = "remote"
MODE_DOMAIN = "domain"
)
type Proxy struct {
ID int `gorm:"column:id"`
Tag string `gorm:"column:tag"`
Enable int `gorm:"column:enable"`
Iface string `gorm:"column:interface"`
Port int `gorm:"column:port"`
Auth int `gorm:"column:auth"`
Protocal string `gorm:"column:protocal"`
Remote string `gorm:"column:remote"`
Mode string `gorm:"column:mode"`
Status string `gorm:"column:status"`
}
const PROXY_TABLE_NAME = "proxys"
func ProxyFind(tag string) *Proxy {
var out Proxy
db := orm.Table(PROXY_TABLE_NAME)
db.Where("tag = ?", tag).First(&out)
if out.ID == 0 {
return nil
}
return &out
}
func ProxyFindByID(id string) *Proxy {
var out Proxy
db := orm.Table(PROXY_TABLE_NAME)
db.Where("id = ?", id).First(&out)
if out.ID == 0 {
return nil
}
return &out
}
func ProxyGet() []Proxy {
var out []Proxy
db := orm.Table(PROXY_TABLE_NAME)
db.Find(&out)
return out
}
func ProxyUpdate(tag string, update func(u *Proxy) ) error {
var info Proxy
db := orm.Table(PROXY_TABLE_NAME)
db.Where("tag = ?", tag).First(&info)
if info.ID == 0 {
return fmt.Errorf("%s not exist", tag)
}
update(&info)
db.Where("id = ?", info.ID).UpdateColumns(info)
return nil
}