speedtest

package
v0.1.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortFieldBandwidth  SortField = "b"         // 带宽
	SortFieldBandwidth2 SortField = "bandwidth" // 带宽
	SortFieldTTFB       SortField = "t"         // 延迟
	SortFieldTTFB2      SortField = "ttfb"

	GPTTestURLAndroid = "https://android.chat.openai.com"
	GPTTestURLIOS     = "https://ios.chat.openai.com/"
	GPTTestURLWeb     = "https://chatgpt.com/"
	GPTTrace          = "https://chat.openai.com/cdn-cgi/trace"

	DefaultLivenessAddr = "https://speed.cloudflare.com/__down?bytes=%d"
)

Variables

View Source
var (
	ErrSpeedNotTest = errors.New("请先测速")
)

Functions

func ReadProxies

func ReadProxies(configPathConfig string, proxyUrl *url.URL) (map[string]CProxy, error)

ReadProxies 从网络下载或者本地读取配置文件 configPathConfig 是配置地址,多个之间用 | 分割

func SetCacheTimeout added in v0.1.2

func SetCacheTimeout(t time.Duration)

func TestURLAvailable added in v0.1.4

func TestURLAvailable(urls []string, proxy C.Proxy, timeout time.Duration) map[string]bool

Types

type CProxy

type CProxy struct {
	C.Proxy
	SecretConfig map[string]any
}

type CProxyWithResult added in v0.0.2

type CProxyWithResult struct {
	Proxies CProxy
	Results Result
}

type GPTResult

type GPTResult struct {
	Android bool   `json:"android"`
	IOS     bool   `json:"ios"`
	Web     bool   `json:"web"`
	Loc     string `json:"loc"`
}

func TestChatGPTAccess

func TestChatGPTAccess(proxy C.Proxy, timeout time.Duration) GPTResult

type Options

type Options struct {
	LivenessAddr        string        `json:"liveness_addr"`          // 测速时调用的地址,格式如 https://speed.cloudflare.com/__down?bytes=%d
	DownloadSize        int           `json:"download_size"`          // 测速时下载的文件大小,单位为 bit(使用默认cloudflare的话),默认下载10M
	Timeout             time.Duration `json:"timeout"`                // 每个代理测速的超时时间
	ConfigPath          string        `json:"config_path"`            // 配置文件地址,可以为 URL 或者本地路径,多个使用 | 分隔
	NameRegexContain    string        `json:"name_regex_contain"`     // 通过名字过滤代理,只测试过滤部分,格式为正则,默认全部测
	NameRegexNonContain string        `json:"name_regex_not_contain"` // 通过名字过滤代理,跳过过滤部分,格式为正则
	SortField           SortField     `json:"sort_field"`             // 排序方式,b 带宽 t 延迟
	Concurrent          int           `json:"concurrent"`             // 测速时候的下载并发数
	TestGPT             bool          `json:"test_gpt"`               // 是否检测节点支持 GPT
	URLForTest          []string      `json:"url_for_test"`           // 测试 URL 是否可访问
	ProxyUrl            string        `json:"proxy_url"`              // ConfigPath 为网络链接时可使用指定代理下载
}

type ProxyProvider added in v0.1.14

type ProxyProvider struct {
	Url string `json:"url"`
}

type RawConfig

type RawConfig struct {
	Providers map[string]ProxyProvider `yaml:"proxy-providers"`
	Proxies   []map[string]any         `yaml:"proxies"`
}

type RequestOption added in v0.1.7

type RequestOption struct {
	Method  string
	URL     string
	Body    []byte
	JSON    interface{} // 传递这个参数可以为任意可 json 序列化值,会自动加上 Content-Type, 并覆盖 Body 内容
	Headers map[string]string
	Timeout time.Duration // 单次请求超时时间
	// 重试相关
	RetryTimes   int           // 重试次数
	RetryTimeOut time.Duration // 重试超时时间
	// 详细日志
	Verbose bool
	// 代理链接
	ProxyUrl *url.URL
}

type Result

type Result struct {
	Name      string
	Bandwidth float64
	TTFB      time.Duration
	Delay     uint16
	GPTResult
	URLForTest map[string]bool
}

func TestProxyConcurrent

func TestProxyConcurrent(name string, proxy C.Proxy, option *Options) *Result

func TestSpeed

func TestSpeed(proxies map[string]CProxy, options *Options) ([]Result, error)

func (*Result) Alive

func (r *Result) Alive() bool

func (*Result) Printf

func (r *Result) Printf(format string)

type SortField

type SortField string

type Test

type Test struct {
	// contains filtered or unexported fields
}

func NewTest

func NewTest(options Options) (*Test, error)

func (*Test) AliveProxies

func (t *Test) AliveProxies() ([]CProxy, error)

AliveProxies 可访问的节点

func (*Test) AliveProxiesToJson

func (t *Test) AliveProxiesToJson() ([]byte, error)

AliveProxiesToJson 可访问的节点, 返回 JSON string

func (*Test) AliveProxiesWithResult added in v0.0.2

func (t *Test) AliveProxiesWithResult() ([]CProxyWithResult, error)

AliveProxiesWithResult 可访问的节点以及结果

func (*Test) LogAlive

func (t *Test) LogAlive()

func (*Test) LogNum

func (t *Test) LogNum()

func (*Test) LogResults

func (t *Test) LogResults()

func (*Test) Proxies

func (t *Test) Proxies() map[string]CProxy

func (*Test) TestSpeed

func (t *Test) TestSpeed() ([]Result, error)

func (*Test) WriteToCsv

func (t *Test) WriteToCsv(names ...string) error

func (*Test) WriteToYaml

func (t *Test) WriteToYaml(names ...string) error

type XcResponse added in v0.1.7

type XcResponse struct {
	Body       []byte
	StatusCode int
}

func Request added in v0.1.7

func Request(option *RequestOption) (*XcResponse, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL