pac

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package pac is the PAC (proxy auto-config) engine: the persisted PAC configuration store and the FindProxyForURL generator. Extracted from package main per ADR-0002; the HTTP handlers, route registration, and the pacStore singleton stay in main (pac.go shim). The former pacDefaultProxyPort package global is now a Store field (SetDefaultPort), set once by the startup slice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ProxyHost is the hostname or IP of this proxy, e.g. "proxy.corp.com".
	// If empty the /proxy.pac endpoint uses the hostname from the request's
	// Host header (stripping the port, which belongs to the UI — not the proxy).
	ProxyHost string `json:"proxyHost"`
	// ProxyPort is the port the proxy server listens on.
	// If zero it falls back to the runtime proxy port set at startup.
	ProxyPort int `json:"proxyPort"`
	// Exclusions is the list of host patterns that should bypass the proxy.
	// Supports bare domains ("corp.local"), wildcard prefixes ("*.corp.local"),
	// and IP CIDR ranges ("192.168.0.0/16").
	Exclusions []string `json:"exclusions"`
}

Config is the persisted PAC configuration.

type State

type State struct {
	Cfg         Config
	Path        string
	DefaultPort int
}

State is a full snapshot of a Store for test isolation (Snapshot/Restore).

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store persists Config to a JSON file.

func (*Store) DefaultPort

func (s *Store) DefaultPort() int

DefaultPort returns the startup-time fallback proxy port (0 if unset).

func (*Store) GeneratePAC

func (s *Store) GeneratePAC(proxyAddr string) string

GeneratePAC builds the PAC JavaScript. proxyAddr is the "host:port" string to use when ProxyHost is empty (caller passes the request's Host as a fallback).

func (*Store) Get

func (s *Store) Get() Config

Get returns a snapshot of the current config.

func (*Store) Load

func (s *Store) Load(path string) error

Load reads config from the JSON file; a missing file is a no-op.

func (*Store) Restore

func (s *Store) Restore(st State)

Restore resets the store to a previously captured State (test support).

func (*Store) Set

func (s *Store) Set(c Config) error

Set replaces the config and persists it.

func (*Store) SetDefaultPort

func (s *Store) SetDefaultPort(port int)

SetDefaultPort records the runtime proxy listening port used as the fallback when Config.ProxyPort is zero. Called once by the startup slice.

func (*Store) Snapshot

func (s *Store) Snapshot() State

Snapshot returns the store's full state. Test support: pair with Restore so tests that mutate the process-wide store stay hermetic under -shuffle.

Jump to

Keyboard shortcuts

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