github.com/kelleygo/clashcore@v1.0.2/constant/provider/interface.go (about) 1 package provider 2 3 import ( 4 "github.com/kelleygo/clashcore/common/utils" 5 "github.com/kelleygo/clashcore/constant" 6 ) 7 8 // Vehicle Type 9 const ( 10 File VehicleType = iota 11 HTTP 12 Compatible 13 ) 14 15 // VehicleType defined 16 type VehicleType int 17 18 func (v VehicleType) String() string { 19 switch v { 20 case File: 21 return "File" 22 case HTTP: 23 return "HTTP" 24 case Compatible: 25 return "Compatible" 26 default: 27 return "Unknown" 28 } 29 } 30 31 type Vehicle interface { 32 Read() ([]byte, error) 33 Path() string 34 Proxy() string 35 Type() VehicleType 36 } 37 38 // Provider Type 39 const ( 40 Proxy ProviderType = iota 41 Rule 42 ) 43 44 // ProviderType defined 45 type ProviderType int 46 47 func (pt ProviderType) String() string { 48 switch pt { 49 case Proxy: 50 return "Proxy" 51 case Rule: 52 return "Rule" 53 default: 54 return "Unknown" 55 } 56 } 57 58 // Provider interface 59 type Provider interface { 60 Name() string 61 VehicleType() VehicleType 62 Type() ProviderType 63 Initial() error 64 Update() error 65 } 66 67 // ProxyProvider interface 68 type ProxyProvider interface { 69 Provider 70 Proxies() []constant.Proxy 71 // Touch is used to inform the provider that the proxy is actually being used while getting the list of proxies. 72 // Commonly used in DialContext and DialPacketConn 73 Touch() 74 HealthCheck() 75 Version() uint32 76 RegisterHealthCheckTask(url string, expectedStatus utils.IntRanges[uint16], filter string, interval uint) 77 HealthCheckURL() string 78 } 79 80 // RuleProvider interface 81 type RuleProvider interface { 82 Provider 83 Behavior() RuleBehavior 84 Match(*constant.Metadata) bool 85 ShouldResolveIP() bool 86 ShouldFindProcess() bool 87 AsRule(adaptor string) constant.Rule 88 } 89 90 // Rule Behavior 91 const ( 92 Domain RuleBehavior = iota 93 IPCIDR 94 Classical 95 ) 96 97 // RuleBehavior defined 98 type RuleBehavior int 99 100 func (rt RuleBehavior) String() string { 101 switch rt { 102 case Domain: 103 return "Domain" 104 case IPCIDR: 105 return "IPCIDR" 106 case Classical: 107 return "Classical" 108 default: 109 return "Unknown" 110 } 111 } 112 113 const ( 114 YamlRule RuleFormat = iota 115 TextRule 116 ) 117 118 type RuleFormat int 119 120 func (rf RuleFormat) String() string { 121 switch rf { 122 case YamlRule: 123 return "YamlRule" 124 case TextRule: 125 return "TextRule" 126 default: 127 return "Unknown" 128 } 129 }