model.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package model
  2. import (
  3. "encoding/json"
  4. "x-ui/xray"
  5. )
  6. type Protocol string
  7. const (
  8. VMess Protocol = "vmess"
  9. VLESS Protocol = "vless"
  10. Dokodemo Protocol = "Dokodemo-door"
  11. Http Protocol = "http"
  12. Trojan Protocol = "trojan"
  13. Shadowsocks Protocol = "shadowsocks"
  14. )
  15. type User struct {
  16. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  17. Username string `json:"username"`
  18. Password string `json:"password"`
  19. }
  20. type Inbound struct {
  21. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  22. UserId int `json:"user_id" form:"user_id"`
  23. Up int64 `json:"up" form:"up"`
  24. Down int64 `json:"down" form:"down"`
  25. Remark string `json:"remark" form:"remark"`
  26. Enable bool `json:"enable" form:"enable"`
  27. ExpiryTime int64 `json:"expiry_time" form:"expiry_time"`
  28. // config part
  29. Listen string `json:"listen" form:"listen"`
  30. Port int `json:"port" form:"port"`
  31. Protocol Protocol `json:"protocol" form:"protocol"`
  32. Settings string `json:"settings" form:"settings"`
  33. StreamSettings string `json:"stream_settings" form:"stream_settings"`
  34. Tag string `json:"tag" form:"tag"`
  35. Sniffing string `json:"sniffing" form:"sniffing"`
  36. }
  37. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  38. return &xray.InboundConfig{
  39. Listen: json.RawMessage(i.Listen),
  40. Port: i.Port,
  41. Protocol: string(i.Protocol),
  42. Settings: json.RawMessage(i.Settings),
  43. StreamSettings: json.RawMessage(i.StreamSettings),
  44. Tag: i.Tag,
  45. Sniffing: json.RawMessage(i.Sniffing),
  46. }
  47. }
  48. type Setting struct {
  49. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  50. Key string `json:"key" form:"key"`
  51. Value string `json:"value" form:"value"`
  52. }