sysproxy

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sysproxy teaches Go's default HTTP transport to honour the proxy configured in the operating system.

A GUI app started by Finder, the Dock or a login item inherits no HTTP_PROXY/HTTPS_PROXY/NO_PROXY variables, so http.ProxyFromEnvironment sees no proxy and every request goes direct. Install replaces the default transport's Proxy with Func, which keeps the environment when it is set and otherwise reads the system settings (macOS scutil, Windows Internet Settings; Linux has no system-wide proxy Go can read).

The system lookup is cached for cacheTTL, so toggling the system proxy is picked up without restarting the app, and every platform implementation bounds its work (macOS kills scutil after two seconds) and falls back to a direct connection on any error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Func

func Func(req *http.Request) (*url.URL, error)

Func is the proxy selector Install installs. It follows HTTP_PROXY, HTTPS_PROXY and NO_PROXY when any of them is set, and otherwise asks the operating system. It never proxies a loopback address and never returns an error: an unavailable system proxy means a direct connection.

Code that builds its own transport instead of using http.DefaultTransport can assign Func to that transport's Proxy field.

func Install

func Install()

Install points http.DefaultTransport's Proxy at Func. Call it once, before the program performs any network request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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