database

package
v0.0.0-...-6f32bf5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDb

func InitDb(dbPath string) (*gorm.DB, error)

InitDb 初始化数据库

Types

type Config

type Config struct {
	Key   string `gorm:"primaryKey;size:255"`
	Value string
}

Config 全局管理配置模型

type Node

type Node struct {
	ID            uint       `gorm:"primaryKey" json:"id"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
	Name          string     `gorm:"size:255;not null" json:"name"`               // 节点名称,如 "香港 01"
	Address       string     `gorm:"size:255;not null" json:"address"`            // 节点对外地址 (域名/IP)
	DetectedIP    string     `gorm:"size:64" json:"detected_ip"`                  // 自动检测到的心跳来源 IP
	Port          int        `gorm:"default:443" json:"port"`                     // 对外端口
	Secret        string     `gorm:"size:255;not null;uniqueIndex" json:"secret"` // 节点通信密钥
	Status        int        `gorm:"default:0" json:"status"`                     // 0: 离线, 1: 在线
	LastHeartbeat *time.Time `json:"last_heartbeat"`                              // 上次心跳时间
	TrafficRate   float64    `gorm:"default:1.0" json:"traffic_rate"`             // 流量结算倍率

	// Clash 订阅所需参数
	WSEnabled bool   `gorm:"default:false" json:"ws_enabled"`              // 是否启用 Websocket
	WSPath    string `gorm:"size:255;default:'/trojan-go'" json:"ws_path"` // Websocket 路径
}

Node 代理节点模型

type User

type User struct {
	ID         uint       `gorm:"primaryKey" json:"id"` // ID 必须显式标记为 id 供前端调用
	CreatedAt  time.Time  `json:"created_at"`
	Username   string     `json:"username"`                                  // 用户名/备注,方便管理区别人
	Hash       string     `gorm:"uniqueIndex;not null;size:255" json:"hash"` // Trojan 密码的 SHA224 哈希值
	Password   string     `json:"password"`                                  // 明文密码(方便管理端查看和分发)
	Quota      int64      `gorm:"default:-1" json:"quota"`                   // 流量限额 (字节, -1 为无限)
	Used       int64      `gorm:"default:0" json:"used"`                     // 已用总流量
	Upload     int64      `gorm:"default:0" json:"upload"`                   // 上传
	Download   int64      `gorm:"default:0" json:"download"`                 // 下载
	ExpiryTime *time.Time `json:"expiry_time"`                               // 过期时间
	IPLimit    int        `gorm:"default:0" json:"ip_limit"`                 // IP 限制数目
	Status     int        `gorm:"default:0" json:"status"`                   // 0: 正常, 1: 禁用
}

User 代理用户模型

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL