Documentation
¶
Overview ¶
Package decodo provides helpers for building Decodo residential proxy credentials, generating proxy URLs, and managing keyed sticky-session pools that can be reused by Go HTTP clients.
Credential Configuration ¶
Create an Auth from your Decodo user credentials:
auth, err := decodo.NewAuth("my-proxy-user", "my-proxy-password")
// NewAuth validates the raw proxy username early and rejects escaped
// or unsupported characters before a request reaches the proxy.
Build a Config describing your desired proxy session and endpoint:
config := decodo.Config{
Auth: auth,
Session: decodo.Session{
Type: decodo.SessionTypeSticky,
DurationMinutes: 10,
Country: "us",
State: "ny", // optional US state filter
City: "new-york", // optional city filter
},
}
Generating Proxy URLs ¶
Produce a proxy URL string suitable for httpcloak or a SOCKS5 dialer:
proxyURL, err := config.ProxyURL()
Sticky Session Pool ¶
For applications handling multiple business keys (e.g., per-user or per-order), use a Pool to manage sticky sessions with automatic rotation:
pool, err := decodo.NewPool(decodo.PoolOptions{Config: config})
lease, err := pool.Get("user-123") // returns same proxy for this key
// ... use lease.ProxyURL with your HTTP client
When a proxy fails, report it and the pool will rotate automatically:
pool.ReportFailure("user-123", decodo.FailureCause{Err: err})
See https://pkg.go.dev/github.com/VectorSprint/go-proxy-pool/pkg/decodo/adapter/httpcloak and https://pkg.go.dev/github.com/VectorSprint/go-proxy-pool/pkg/decodo/adapter/nethttp for adapter packages that convert Config or Lease into proxy strings compatible with popular Go HTTP libraries.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auth ¶
Auth stores the raw Decodo proxy username and password from the dashboard.
func NewAuth ¶
NewAuth validates and normalizes raw Decodo dashboard credentials.
Example ¶
package main
import (
"fmt"
"github.com/VectorSprint/go-proxy-pool/pkg/decodo"
)
func main() {
auth, err := decodo.NewAuth("my-proxy-user", "my-proxy-password")
if err != nil {
panic(err)
}
cfg := decodo.Config{
Auth: auth,
Targeting: decodo.Targeting{
Country: "us",
City: "new_york",
},
Session: decodo.Session{
Type: decodo.SessionTypeSticky,
ID: "account-1",
DurationMinutes: 30,
},
}
proxyURL, err := cfg.ProxyURL()
if err != nil {
panic(err)
}
fmt.Println(proxyURL.String())
}
Output: http://user-my-proxy-user-country-us-city-new_york-session-account-1-sessionduration-30:my-proxy-password@gate.decodo.com:7000
Example (InvalidUsername) ¶
package main
import (
"fmt"
"github.com/VectorSprint/go-proxy-pool/pkg/decodo"
)
func main() {
_, err := decodo.NewAuth("my%2Fproxy%2Fuser", "my-proxy-password")
fmt.Println(err)
}
Output: username contains invalid characters; only letters, digits, dot, underscore, and hyphen are allowed
type Config ¶
type Config struct {
Auth Auth
EndpointSpec EndpointSpec
Endpoint string
Port int
Targeting Targeting
Session Session
}
Config describes a Decodo user:pass backconnect proxy configuration.
func (*Config) ApplyPreset ¶ added in v0.3.0
func (c *Config) ApplyPreset()
ApplyPreset updates the EndpointSpec to match the targeting configuration using well-known Decodo endpoint presets. If no matching preset is found, no changes are made. This allows targeting to automatically select the correct endpoint, port, and sticky port range.
func (Config) Normalized ¶
Normalized returns a copy of the configuration with defaults and normalized tokens applied.
func (Config) Preset ¶ added in v0.3.0
func (c Config) Preset() (EndpointPreset, bool)
Preset returns the endpoint preset for the configured targeting, or a false ok return if none match.
func (Config) ProxyURL ¶
ProxyURL builds an authenticated Decodo proxy URL suitable for HTTP proxy clients.
func (Config) ProxyUsername ¶
ProxyUsername builds the Decodo proxy username, including targeting and session parameters.
func (Config) Validate ¶
Validate checks whether the configuration satisfies Decodo parameter constraints.
func (Config) ValidateShallow ¶
ValidateShallow checks lightweight structural constraints before full validation.
type EndpointPreset ¶ added in v0.3.0
EndpointPreset describes a known Decodo endpoint with its rotating port and sticky port range.
type EndpointSpec ¶ added in v0.2.0
EndpointSpec describes a Decodo endpoint together with its rotating port and sticky port range.
func NewEndpointSpec ¶ added in v0.2.0
func NewEndpointSpec(host string, rotatingPort int, stickyPortRange PortRange) (EndpointSpec, error)
NewEndpointSpec validates and returns a Decodo endpoint specification.
func (EndpointSpec) IsZero ¶ added in v0.2.0
func (e EndpointSpec) IsZero() bool
IsZero reports whether the endpoint specification is unset.
func (EndpointSpec) Validate ¶ added in v0.2.0
func (e EndpointSpec) Validate() error
Validate checks whether the endpoint specification is structurally valid.
type FailureCause ¶
FailureCause represents a proxy failure reported by the caller to Pool.ReportFailure.
type Lease ¶
Lease represents a resolved sticky-session proxy assignment for a business key. Obtain a lease by calling Pool.Get. The lease remains valid until its ExpiresAt time has passed, unless explicitly rotated via Pool.Rotate.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages sticky-session proxy leases, each keyed by a caller-defined business identifier (e.g., user ID, order ID). The Pool ensures that each key consistently uses the same residential proxy for the session duration, then rotates automatically.
func NewPool ¶
func NewPool(options PoolOptions) (*Pool, error)
NewPool creates a keyed sticky-session Pool from a Decodo Config. The Config must have Session.Type set to SessionTypeSticky. NewPool returns an error if the config validation fails or if a sticky session is not requested.
func (*Pool) CleanupExpired ¶
CleanupExpired removes all expired leases from the pool and returns the number of entries deleted. Call this periodically (e.g., via a background goroutine) to prevent the pool from accumulating stale entries.
func (*Pool) Get ¶
Get returns the active Lease for the given business key. If no active lease exists or the existing lease has expired, a new one is allocated automatically.
Example ¶
package main
import (
"fmt"
"github.com/VectorSprint/go-proxy-pool/pkg/decodo"
decodohttpcloak "github.com/VectorSprint/go-proxy-pool/pkg/decodo/adapter/httpcloak"
)
func main() {
auth, err := decodo.NewAuth("my-proxy-user", "my-proxy-password")
if err != nil {
panic(err)
}
pool, err := decodo.NewPool(decodo.PoolOptions{
Config: decodo.Config{
Auth: auth,
Session: decodo.Session{
Type: decodo.SessionTypeSticky,
DurationMinutes: 30,
},
},
NewSessionID: func(key string) string {
return "session-" + key
},
})
if err != nil {
panic(err)
}
lease, err := pool.Get("account-1")
if err != nil {
panic(err)
}
fmt.Println(decodohttpcloak.ProxyStringFromLease(lease))
}
Output: http://user-my-proxy-user-session-session-account-1-sessionduration-30:my-proxy-password@gate.decodo.com:7000
func (*Pool) ReportFailure ¶
func (p *Pool) ReportFailure(key string, _ FailureCause) error
ReportFailure records a failure for the given key. When the number of recorded failures reaches FailureThreshold, the lease is rotated automatically.
type PoolOptions ¶
type PoolOptions struct {
Config Config
FailureThreshold int
Now func() time.Time
NewSessionID func(key string) string
// RandomPort selects a random sticky port from the available range instead of
// sequentially allocating ports. This reduces detection risk when using a single
// endpoint with many sessions.
RandomPort bool
// Rand is the random source for port selection. If nil, math/rand is used.
Rand *rand.Rand
}
PoolOptions configures how a keyed sticky-session Pool behaves.
type PortRange ¶ added in v0.2.0
PortRange describes an inclusive port range.
func (PortRange) Contains ¶ added in v0.2.0
Contains reports whether the range includes the provided port.
type Session ¶
type Session struct {
Type SessionType
ID string
DurationMinutes int
}
Session describes whether requests should rotate IPs or reuse a sticky session.
type SessionType ¶
type SessionType string
const ( // SessionTypeRotating requests a new residential IP on each proxy request. SessionTypeRotating SessionType = "rotating" // SessionTypeSticky keeps the same residential IP for the configured session duration. SessionTypeSticky SessionType = "sticky" )
Directories
¶
| Path | Synopsis |
|---|---|
|
adapter
|
|
|
httpcloak
Package httpcloak exposes helpers that adapt decodo configuration and leases into proxy strings accepted by github.com/sardanioss/httpcloak.
|
Package httpcloak exposes helpers that adapt decodo configuration and leases into proxy strings accepted by github.com/sardanioss/httpcloak. |
|
nethttp
Package nethttp exposes helpers that adapt decodo configuration and leases into proxy values accepted by the Go standard library net/http package.
|
Package nethttp exposes helpers that adapt decodo configuration and leases into proxy values accepted by the Go standard library net/http package. |