Files
x-ui/database/model/model.go
2021-05-27 23:04:39 +08:00

61 lines
1.8 KiB
Go

package model
import (
"encoding/json"
"x-ui/xray"
)
type Protocol string
const (
VMess Protocol = "vmess"
VLESS Protocol = "vless"
Dokodemo Protocol = "Dokodemo-door"
Http Protocol = "http"
Trojan Protocol = "trojan"
Shadowsocks Protocol = "shadowsocks"
)
type User struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username"`
Password string `json:"password"`
}
type Inbound struct {
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
UserId int `json:"user_id" form:"user_id"`
Up int64 `json:"up" form:"up"`
Down int64 `json:"down" form:"down"`
Remark string `json:"remark" form:"remark"`
Enable bool `json:"enable" form:"enable"`
ExpiryTime int64 `json:"expiry_time" form:"expiry_time"`
// config part
Listen string `json:"listen" form:"listen"`
Port int `json:"port" form:"port"`
Protocol Protocol `json:"protocol" form:"protocol"`
Settings string `json:"settings" form:"settings"`
StreamSettings string `json:"stream_settings" form:"stream_settings"`
Tag string `json:"tag" form:"tag"`
Sniffing string `json:"sniffing" form:"sniffing"`
}
func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
return &xray.InboundConfig{
Listen: i.Listen,
Port: i.Port,
Protocol: string(i.Protocol),
Settings: json.RawMessage(i.Settings),
StreamSettings: json.RawMessage(i.StreamSettings),
Tag: i.Tag,
Sniffing: json.RawMessage(i.Sniffing),
}
}
type Setting struct {
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
Key string `json:"key" form:"key"`
Value string `json:"value" form:"value"`
}