| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package model
- import "time"
- // Proxy stores network proxy configurations for task execution.
- type Proxy struct {
- ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
- Name string `gorm:"size:100;not null" json:"name"`
- Protocol string `gorm:"size:20;not null;default:'http'" json:"protocol"` // http / https / socks5
- Host string `gorm:"size:255;not null" json:"host"`
- Port int `gorm:"not null" json:"port"`
- Username string `gorm:"size:100" json:"username"`
- Password string `gorm:"size:100" json:"password"`
- Region string `gorm:"size:50" json:"region"` // 地区标签,如 US / HK / JP
- Enabled bool `gorm:"default:true" json:"enabled"`
- Status string `gorm:"size:20;default:'unknown'" json:"status"` // unknown / ok / fail
- LastCheckedAt *time.Time `json:"last_checked_at"`
- Remark string `gorm:"size:500" json:"remark"`
- CreatedAt time.Time `json:"created_at"`
- UpdatedAt time.Time `json:"updated_at"`
- }
- func (Proxy) TableName() string { return "proxies" }
- // ProxyURL returns the full proxy URL string for HTTP clients.
- func (p Proxy) ProxyURL() string {
- auth := ""
- if p.Username != "" {
- auth = p.Username
- if p.Password != "" {
- auth += ":" + p.Password
- }
- auth += "@"
- }
- return p.Protocol + "://" + auth + p.Host + ":" + itoa(p.Port)
- }
- func itoa(n int) string {
- if n == 0 {
- return "0"
- }
- s := ""
- for n > 0 {
- s = string(rune('0'+n%10)) + s
- n /= 10
- }
- return s
- }
|