clash

package
v0.0.0-...-36cf133 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FilterByCountry

func FilterByCountry(codes ...string) func(ProxyNode) bool

FilterByCountry returns a filter function for use with clash.Options.Filter that keeps nodes whose server IP resolves to one of the given country codes.

func FilterByName

func FilterByName(keyword string) func(ProxyNode) bool

FilterByName returns a filter function that keeps nodes whose name contains the keyword.

func FilterByType

func FilterByType(types ...string) func(ProxyNode) bool

FilterByType returns a filter function that only keeps nodes of the given types.

func HealthyDials

func HealthyDials(results []NodeResult) []proxyclient.Dial

HealthyDials returns only the working Dial functions from health check results.

func NodeToURL

func NodeToURL(node map[string]any) (*url.URL, error)

Types

type GeoLookup

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

func Geo

func Geo() *GeoLookup

Geo returns the shared GeoLookup instance, initialized on first call.

func (*GeoLookup) LookupIP

func (g *GeoLookup) LookupIP(ipStr string) (string, bool)

LookupIP returns the 2-letter country code for an IPv4 address string.

func (*GeoLookup) ResolveAndLookup

func (g *GeoLookup) ResolveAndLookup(host string) (string, bool)

ResolveAndLookup resolves a hostname to an IP, then looks up the country.

type HealthCheckConfig

type HealthCheckConfig struct {
	URL         string        // test URL, default: google generate_204
	Timeout     time.Duration // per-node timeout, default: 10s
	Concurrency int           // max concurrent tests, default: 20
}

type NodeResult

type NodeResult struct {
	Node    ProxyNode
	Dial    proxyclient.Dial
	Latency time.Duration
	Err     error
}

func HealthCheck

func HealthCheck(sub *Subscription, cfg *HealthCheckConfig, filter func(ProxyNode) bool) []NodeResult

HealthCheck tests all dialable nodes concurrently and returns results sorted by latency.

type Options

type Options struct {
	Strategy    Strategy
	Filter      func(node ProxyNode) bool
	HealthCheck *HealthCheckConfig // used by url-test strategy, or set to enable pre-filtering
	// UserAgent for fetching subscription. Default: "clash".
	UserAgent string
}

type ProxyGroup

type ProxyGroup struct {
	Name    string
	Type    string   // select, url-test, fallback, load-balance
	Proxies []string // member proxy names
}

type ProxyNode

type ProxyNode struct {
	Name      string
	Type      string // ss, socks5, trojan, vmess, vless, hysteria2, http
	Server    string
	Port      int
	URL       *url.URL
	RawConf   map[string]any
	Supported bool
}

func DialableNodes

func DialableNodes(sub *Subscription) []ProxyNode

DialableNodes returns nodes whose URL scheme is registered in proxyclient.

func NodesByType

func NodesByType(sub *Subscription, proxyType string) []ProxyNode

func SupportedNodes

func SupportedNodes(sub *Subscription) []ProxyNode

type Strategy

type Strategy string
const (
	StrategyRoundRobin Strategy = "round-robin"
	StrategyRandom     Strategy = "random"
	StrategyHash       Strategy = "hash"
	StrategyFirst      Strategy = "first"
	StrategyURLTest    Strategy = "url-test" // health check, then use fastest nodes
	StrategyAdaptive   Strategy = "adaptive" // auto-learn from success/failure/latency
)

type Subscription

type Subscription struct {
	Nodes  []ProxyNode
	Groups []ProxyGroup
}

func FetchSubscription

func FetchSubscription(subscribeURL string) (*Subscription, error)

func FetchSubscriptionWithUA

func FetchSubscriptionWithUA(subscribeURL, userAgent string) (*Subscription, error)

FetchSubscriptionWithUA fetches a subscription with the given User-Agent.

func NewDialer

func NewDialer(subscribeURL string, opts Options) (proxyclient.Dial, *Subscription, error)

NewDialer fetches a Clash subscription URL, parses it, creates proxyclient dialers for all dialable nodes, and returns a single load-balanced Dial.

func NewDialerFromSubscription

func NewDialerFromSubscription(sub *Subscription, opts Options) (proxyclient.Dial, *Subscription, error)

NewDialerFromSubscription creates a load-balanced Dial from a pre-parsed subscription.

func ParseSubscription

func ParseSubscription(data []byte) (*Subscription, error)

Jump to

Keyboard shortcuts

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