Documentation
¶
Overview ¶
Package proxykit defines proxy addresses, schemes, credentials, and validation helpers.
Index ¶
- func IsValidCredentials(username, password string) bool
- func IsValidHostnamePort(hnp string) bool
- func IsValidScheme(s ProxyScheme) bool
- type Proxy
- func (p *Proxy) ExportURL() *url.URL
- func (p *Proxy) GetHost() string
- func (p *Proxy) GetPassword() string
- func (p *Proxy) GetScheme() ProxyScheme
- func (p *Proxy) GetUsername() string
- func (p *Proxy) IsCredentialFilled() bool
- func (p *Proxy) IsValid() bool
- func (p *Proxy) IsValidCredentials() bool
- func (p *Proxy) IsValidHostnamePort() bool
- func (p *Proxy) IsValidScheme() bool
- func (p Proxy) IsZero() bool
- func (p *Proxy) Reset()
- func (p *Proxy) SetHost(s string)
- func (p *Proxy) SetPassword(s string)
- func (p *Proxy) SetScheme(s ProxyScheme)
- func (p *Proxy) SetUsername(s string)
- type ProxyGetter
- type ProxyProvider
- type ProxyResetter
- type ProxyScheme
- type ProxySetter
- type ProxyValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidCredentials ¶
IsValidCredentials reports whether username and password form valid proxy credentials. Each value may contain at most 255 bytes and no ASCII control bytes. A non-empty password requires a non-empty username.
func IsValidHostnamePort ¶
IsValidHostnamePort reports whether hnp is a valid host-port pair. The port must be between 1 and 65535. A non-empty host must contain only letters, decimal digits, hyphens, and dot-separated labels of at most 63 bytes.
func IsValidScheme ¶
func IsValidScheme(s ProxyScheme) bool
IsValidScheme reports whether s is a supported proxy scheme. It returns true for HTTP, HTTPS, SOCKS5, and SOCKS5H.
Types ¶
type Proxy ¶
type Proxy struct {
Scheme ProxyScheme `json:"scheme,omitempty" validate:"required_with=Host,omitempty,lowercase,oneof=http https socks5 socks5h"`
Host string `json:"host,omitempty" validate:"required_with=Scheme,omitempty,hostname_port"`
Username string `json:"username,omitempty" validate:"required_with_all=Scheme Host Password,omitempty,printascii,max=255"`
Password string `json:"password,omitempty" validate:"omitempty,printascii,max=255"`
}
Proxy represents a proxy endpoint and its optional credentials.
func (*Proxy) ExportURL ¶
ExportURL returns a url.URL containing p's scheme, host, and credentials. It returns nil when p is nil.
func (*Proxy) GetHost ¶
GetHost returns p's host and port. It returns an empty string when p is nil.
func (*Proxy) GetPassword ¶
GetPassword returns p's password. It returns an empty string when p is nil.
func (*Proxy) GetScheme ¶
func (p *Proxy) GetScheme() ProxyScheme
GetScheme returns p's ProxyScheme. It returns the zero scheme when p is nil.
func (*Proxy) GetUsername ¶
GetUsername returns p's username. It returns an empty string when p is nil.
func (*Proxy) IsCredentialFilled ¶
IsCredentialFilled reports whether p has a username. It reports false when p is nil.
func (*Proxy) IsValid ¶
IsValid reports whether p passes Proxy.IsValidScheme, Proxy.IsValidHostnamePort, and Proxy.IsValidCredentials.
func (*Proxy) IsValidCredentials ¶ added in v0.2.0
IsValidCredentials reports whether p's credentials pass IsValidCredentials.
func (*Proxy) IsValidHostnamePort ¶ added in v0.2.0
IsValidHostnamePort reports whether p's host passes IsValidHostnamePort.
func (*Proxy) IsValidScheme ¶ added in v0.2.0
IsValidScheme reports whether p's scheme passes IsValidScheme.
func (*Proxy) Reset ¶
func (p *Proxy) Reset()
Reset clears every field in p. It has no effect when p is nil.
func (*Proxy) SetPassword ¶
SetPassword sets p's password when s is at most 255 bytes. It has no effect when p is nil or s is longer than 255 bytes.
func (*Proxy) SetScheme ¶
func (p *Proxy) SetScheme(s ProxyScheme)
SetScheme sets p's ProxyScheme. It has no effect when p is nil.
func (*Proxy) SetUsername ¶
SetUsername sets p's username when s is at most 255 bytes. It has no effect when p is nil or s is longer than 255 bytes.
type ProxyGetter ¶
type ProxyGetter interface {
// ExportURL returns the proxy as a [url.URL].
ExportURL() *url.URL
// GetHost returns the proxy host and port.
GetHost() string
// GetPassword returns the proxy password.
GetPassword() string
// GetScheme returns the proxy scheme.
GetScheme() ProxyScheme
// GetUsername returns the proxy username.
GetUsername() string
ProxyValidator
}
ProxyGetter describes read access to proxy fields and validation.
type ProxyProvider ¶
type ProxyProvider interface {
ProxyGetter
ProxySetter
}
ProxyProvider combines ProxyGetter and ProxySetter.
type ProxyResetter ¶
type ProxyResetter interface {
// Reset clears every proxy field.
Reset()
}
ProxyResetter describes a proxy reset operation.
type ProxyScheme ¶
type ProxyScheme string
ProxyScheme identifies a proxy protocol accepted by IsValidScheme.
const ( // HTTP is the [ProxyScheme] for an HTTP proxy. HTTP ProxyScheme = "http" // HTTPS is the [ProxyScheme] for an HTTPS proxy. HTTPS ProxyScheme = "https" // SOCKS5 is the [ProxyScheme] for a SOCKS5 proxy. SOCKS5 ProxyScheme = "socks5" // SOCKS5H is the [ProxyScheme] for a SOCKS5 proxy that resolves hostnames remotely. SOCKS5H ProxyScheme = "socks5h" )
func (ProxyScheme) String ¶
func (s ProxyScheme) String() string
String returns the string representation of s.
type ProxySetter ¶
type ProxySetter interface {
// SetHost sets the proxy host and port.
SetHost(s string)
// SetPassword sets the proxy password.
SetPassword(s string)
// SetScheme sets the proxy scheme.
SetScheme(s string)
// SetUsername sets the proxy username.
SetUsername(s string)
ProxyResetter
}
ProxySetter describes write access to proxy fields.
type ProxyValidator ¶
type ProxyValidator interface {
// IsCredentialFilled reports whether the proxy has a username.
IsCredentialFilled() bool
// IsValidCredentials reports whether the proxy credentials are valid.
IsValidCredentials() bool
// IsValidHostnamePort reports whether the proxy host and port are valid.
IsValidHostnamePort() bool
// IsValidScheme reports whether the proxy scheme is supported.
IsValidScheme() bool
// IsValid reports whether the proxy fields are valid.
IsValid() bool
// IsZero reports whether every proxy field is empty.
IsZero() bool
}
ProxyValidator describes proxy state and validation methods.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package proxyparser compiles proxy formats and parses proxy strings into proxykit.Proxy values.
|
Package proxyparser compiles proxy formats and parses proxy strings into proxykit.Proxy values. |
|
Package proxypool provides concurrent iteration over proxies stored one per line in a text file.
|
Package proxypool provides concurrent iteration over proxies stored one per line in a text file. |