Sub2API v1.0 - AI API 网关(二开初始版本,基于上游 Wei-Shaw/sub2api)
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
Release / update-version (push) Has been cancelled
Release / build-frontend (push) Has been cancelled
Release / release (push) Has been cancelled
Release / sync-version-file (push) Has been cancelled
CI / shell (push) Canceled after 0s
CI / test (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
Security Scan / backend-security (push) Canceled after 0s
Security Scan / frontend-security (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
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)),
|
||||
}
|
||||
if p.Username != "" && p.Password != "" {
|
||||
u.User = url.UserPassword(p.Username, 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
|
||||
}
|
||||
Reference in New Issue
Block a user