-
Notifications
You must be signed in to change notification settings - Fork 465
/
db.go
75 lines (62 loc) · 1.37 KB
/
db.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
75
package v2ray_ssrpanel_plugin
import (
"github.com/jinzhu/gorm"
"time"
)
type UserModel struct {
ID uint
VmessID string
Email string `gorm:"column:username"`
}
func (*UserModel) TableName() string {
return "user"
}
type UserTrafficLog struct {
ID uint `gorm:"primary_key"`
UserID uint
Uplink uint64 `gorm:"column:u"`
Downlink uint64 `gorm:"column:d"`
NodeID uint
Rate float64
Traffic string
LogTime int64
}
func (l *UserTrafficLog) BeforeCreate(scope *gorm.Scope) error {
l.LogTime = time.Now().Unix()
return nil
}
type NodeOnlineLog struct {
ID uint `gorm:"primary_key"`
NodeID uint
OnlineUser int
LogTime int64
}
func (*NodeOnlineLog) TableName() string {
return "ss_node_online_log"
}
func (l *NodeOnlineLog) BeforeCreate(scope *gorm.Scope) error {
l.LogTime = time.Now().Unix()
return nil
}
type NodeInfo struct {
ID uint `gorm:"primary_key"`
NodeID uint
Uptime time.Duration
Load string
LogTime int64
}
func (*NodeInfo) TableName() string {
return "ss_node_info"
}
func (l *NodeInfo) BeforeCreate(scope *gorm.Scope) error {
l.LogTime = time.Now().Unix()
return nil
}
type DB struct {
DB *gorm.DB
}
func (db *DB) GetAllUsers() ([]UserModel, error) {
users := make([]UserModel, 0)
db.DB.Select("id, vmess_id, username").Where("enable = 1 AND u + d < transfer_enable").Find(&users)
return users, nil
}