detect

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package detect discovers system proxy configurations from one or more sources (environment variables, the Windows WinINET registry, etc.) and exposes them as a uniform list of [Candidate]s.

Each platform-specific file registers its detector into Default at init time; downstream consumers call All to retrieve the merged candidate list, or instantiate a specific Detector by hand for finer control.

Index

Constants

This section is empty.

Variables

View Source
var Default []Detector

Default is the list of detectors used by All. Each platform- specific file (env.go, wininet_windows.go, ...) appends its own detector at init time.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	// URL is the proxy URL with no userinfo, e.g. "http://proxy:8080"
	// or "socks5://proxy:1080".
	URL string

	// User and Pass are the credentials, when the source provided
	// them inline (e.g. HTTP_PROXY=http://user:pass@proxy:8080).
	// Both empty when no userinfo was attached.
	User string
	Pass string

	// From identifies the source detector — "env", "wininet",
	// "linux/gnome", etc. Useful for diagnostics and precedence
	// decisions in the caller.
	From string
}

Candidate is a discovered proxy configuration.

func All

func All() ([]Candidate, error)

All runs every detector in Default in order and concatenates their candidates. Per-detector errors are collected and joined; one source failing does not stop the others.

type Detector

type Detector interface {
	// Detect inspects the source and returns any proxy candidates
	// it finds. An empty slice + nil error means "source consulted,
	// nothing configured".
	Detect() ([]Candidate, error)
}

Detector returns proxy candidates from a single source.

type EnvDetector

type EnvDetector struct{}

EnvDetector reads the standard *_PROXY environment variables via golang.org/x/net/http/httpproxy.FromEnvironment, which honours both upper-case (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) and lower-case (http_proxy, https_proxy, no_proxy) names per the longstanding libcurl convention.

At most two candidates are returned (one for HTTPProxy, one for HTTPSProxy); duplicates are coalesced.

func (EnvDetector) Detect

func (EnvDetector) Detect() ([]Candidate, error)

Detect returns the proxy candidates implied by the current process environment.

type WinINETDetector

type WinINETDetector struct{}

WinINETDetector exists on non-Windows builds so the type itself is referable from cross-platform code (e.g. tests asserting type identity), but its Detect is a no-op and it is NOT registered into detect.Default — auto-discovery via detect.All only runs detectors relevant to the host platform.

func (WinINETDetector) Detect

func (WinINETDetector) Detect() ([]Candidate, error)

Detect always returns no candidates on non-Windows builds.

Jump to

Keyboard shortcuts

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