| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package service
- import (
- "net"
- "net/url"
- "strconv"
- "time"
- )
- const (
- FallbackModeNone = "none"
- FallbackModeProxy = "proxy"
- FallbackModeDirect = "direct"
- )
- type Proxy struct {
- ID int64
- Name string
- Protocol string
- Host string
- Port int
- Username string
- Password string
- Status string
- CreatedAt time.Time
- UpdatedAt time.Time
- ExpiresAt *time.Time
- FallbackMode string
- BackupProxyID *int64
- ExpiryWarnDays int
- }
- func (p *Proxy) IsActive() bool {
- return p.Status == StatusActive
- }
- // IsExpired 报告代理是否已过期(基于 expires_at,与 status 无关)。
- func (p *Proxy) IsExpired(now time.Time) bool {
- return p.ExpiresAt != nil && !p.ExpiresAt.After(now)
- }
- func (p *Proxy) URL() string {
- u := &url.URL{
- Scheme: p.Protocol,
- Host: net.JoinHostPort(p.Host, strconv.Itoa(p.Port)),
- }
- switch {
- case p.Username != "" && p.Password != "":
- u.User = url.UserPassword(p.Username, p.Password)
- case p.Username != "":
- // Preserve credentials when a proxy only requires a username.
- u.User = url.User(p.Username)
- case p.Password != "":
- // A few proxy providers use an empty username with a password.
- u.User = url.UserPassword("", p.Password)
- }
- return u.String()
- }
- type ProxyWithAccountCount struct {
- Proxy
- AccountCount int64
- LatencyMs *int64
- LatencyStatus string
- LatencyMessage string
- IPAddress string
- Country string
- CountryCode string
- Region string
- City string
- QualityStatus string
- QualityScore *int
- QualityGrade string
- QualitySummary string
- QualityChecked *int64
- }
- type ProxyAccountSummary struct {
- ID int64
- Name string
- Platform string
- Type string
- Notes *string
- }
|