mirror of
https://github.com/aykhans/sarin.git
synced 2026-02-27 22:39:13 +00:00
Replace ad-hoc fmt.Errorf/errors.New calls with typed error structs across config, sarin, and script packages to enable type-based error handling. Add script-specific error handlers in CLI entry point. Fix variable shadowing bug in Worker for scriptTransformer. Bump Go to 1.25.7 and golangci-lint to v2.8.0.
44 lines
879 B
Go
44 lines
879 B
Go
package types
|
|
|
|
import (
|
|
"net/url"
|
|
)
|
|
|
|
type Proxy url.URL
|
|
|
|
func (proxy Proxy) String() string {
|
|
return (*url.URL)(&proxy).String()
|
|
}
|
|
|
|
type Proxies []Proxy
|
|
|
|
func (proxies *Proxies) Append(proxy ...Proxy) {
|
|
*proxies = append(*proxies, proxy...)
|
|
}
|
|
|
|
// Parse parses a raw proxy string and appends it to the list.
|
|
// It can return the following errors:
|
|
// - ProxyParseError
|
|
func (proxies *Proxies) Parse(rawValue string) error {
|
|
parsedProxy, err := ParseProxy(rawValue)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
proxies.Append(*parsedProxy)
|
|
return nil
|
|
}
|
|
|
|
// ParseProxy parses a raw proxy URL string into a Proxy.
|
|
// It can return the following errors:
|
|
// - ProxyParseError
|
|
func ParseProxy(rawValue string) (*Proxy, error) {
|
|
urlParsed, err := url.Parse(rawValue)
|
|
if err != nil {
|
|
return nil, NewProxyParseError(err)
|
|
}
|
|
|
|
proxyParsed := Proxy(*urlParsed)
|
|
return &proxyParsed, nil
|
|
}
|