sysproxy

package
v0.9.7-dev.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: GPL-3.0 Imports: 5 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 provides OS system HTTP(S) proxy control and ownership helpers.

Platform backends implement unexported get/enable/disable:

  • Windows: WinINET registry (HKCU or console-user hive under LocalSystem)
  • macOS: networksetup for web/secure-web proxies
  • Linux: GNOME gsettings (best effort)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disable

func Disable() error

Disable turns off the system proxy via the platform backend.

func Enable

func Enable(host string, port int) error

Enable turns on the system proxy for host:port. Blank host defaults to 127.0.0.1. Port must be in 1..65535.

func IsForeign

func IsForeign(observed State, target string) bool

IsForeign reports whether observed system proxy is enabled to a non-empty server that is not owned by the given target.

func IsOwned

func IsOwned(observed State, target string) bool

IsOwned reports whether observed system proxy is enabled and matches target. target is the expected server string (e.g. from NormalizeServer).

func NormalizeServer

func NormalizeServer(host string, port int) string

NormalizeServer formats host and port as a proxy server string (net.JoinHostPort).

Types

type Backend

type Backend interface {
	Get() (State, error)
	Enable(host string, port int) error
	Disable() error
}

Backend is an injectable system-proxy driver for tests and runtime wiring.

func Platform

func Platform() Backend

Platform returns the default OS-backed Backend.

type FakeBackend

type FakeBackend struct {
	State State

	GetErr     error
	EnableErr  error
	DisableErr error

	GetCalls       int
	EnableCalls    int
	DisableCalls   int
	LastEnableHost string
	LastEnablePort int
}

FakeBackend is an in-memory Backend for tests. It records call counts and last args.

func (*FakeBackend) Disable

func (f *FakeBackend) Disable() error

Disable records the call, clears Enabled, or returns DisableErr.

func (*FakeBackend) Enable

func (f *FakeBackend) Enable(host string, port int) error

Enable records host/port, sets State to enabled, or returns EnableErr.

func (*FakeBackend) Get

func (f *FakeBackend) Get() (State, error)

Get returns the fake state or GetErr.

type PlatformBackend

type PlatformBackend struct{}

PlatformBackend adapts package-level Get/Enable/Disable to Backend.

func (PlatformBackend) Disable

func (PlatformBackend) Disable() error

Disable turns off the system proxy via the platform backend.

func (PlatformBackend) Enable

func (PlatformBackend) Enable(host string, port int) error

Enable turns on the system proxy for host:port.

func (PlatformBackend) Get

func (PlatformBackend) Get() (State, error)

Get returns the current system proxy state from the platform backend.

type State

type State struct {
	Enabled bool
	Server  string
}

State is the observed system proxy configuration.

func Get

func Get() (State, error)

Get returns the current system proxy state from the platform backend.

Jump to

Keyboard shortcuts

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