Some checks failed
Build Multi-Platform Binaries / build-frontend (push) Successful in 34s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 1m20s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m33s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 1m16s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m48s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 1m7s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m46s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 1m31s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m58s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 1m35s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Has been cancelled
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Has been cancelled
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package db
|
|
|
|
import "github.com/gotunnel/pkg/protocol"
|
|
|
|
// Client 客户端数据
|
|
type Client struct {
|
|
ID string `json:"id"`
|
|
Nickname string `json:"nickname,omitempty"`
|
|
Rules []protocol.ProxyRule `json:"rules"`
|
|
}
|
|
|
|
// ClientStore 客户端存储接口
|
|
type ClientStore interface {
|
|
GetAllClients() ([]Client, error)
|
|
GetClient(id string) (*Client, error)
|
|
CreateClient(c *Client) error
|
|
UpdateClient(c *Client) error
|
|
DeleteClient(id string) error
|
|
ClientExists(id string) (bool, error)
|
|
GetClientRules(id string) ([]protocol.ProxyRule, error)
|
|
Close() error
|
|
}
|
|
|
|
// Store 统一存储接口
|
|
type Store interface {
|
|
ClientStore
|
|
TrafficStore
|
|
Close() error
|
|
}
|
|
|
|
// TrafficRecord 流量记录
|
|
type TrafficRecord struct {
|
|
Timestamp int64 `json:"timestamp"` // Unix 时间戳(小时级别)
|
|
Inbound int64 `json:"inbound"` // 入站流量(字节)
|
|
Outbound int64 `json:"outbound"` // 出站流量(字节)
|
|
}
|
|
|
|
// TrafficStore 流量存储接口
|
|
type TrafficStore interface {
|
|
AddTraffic(inbound, outbound int64) error
|
|
GetTotalTraffic() (inbound, outbound int64, err error)
|
|
Get24HourTraffic() (inbound, outbound int64, err error)
|
|
GetHourlyTraffic(hours int) ([]TrafficRecord, error)
|
|
}
|
|
|
|
// InstallToken 安装token
|
|
type InstallToken struct {
|
|
Token string `json:"token"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
Used bool `json:"used"`
|
|
}
|
|
|
|
// InstallTokenStore 安装token存储接口
|
|
type InstallTokenStore interface {
|
|
CreateInstallToken(token *InstallToken) error
|
|
GetInstallToken(token string) (*InstallToken, error)
|
|
MarkTokenUsed(token string) error
|
|
DeleteExpiredTokens(expireTime int64) error
|
|
}
|