proxyruntime

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package proxyruntime manages long-lived proxy listeners such as HTTP forward-proxy and SOCKS5 endpoints.

It is transport-agnostic at the application level: it owns lifecycle, restart semantics, and port conflict diagnostics, but it does not know about UI endpoints, persistence, or capture storage.

Example
manager := New(nil)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.WriteHeader(http.StatusOK)
	_, _ = w.Write([]byte("ok"))
})

if err := manager.Apply(context.Background(), ApplyConfig{
	ForwardEnabled: true,
	ForwardAddr:    "127.0.0.1:0",
	SocksEnabled:   true,
	SocksAddr:      "127.0.0.1:0",
}, handler); err != nil {
	panic(err)
}
defer func() {
	_ = manager.StopForward(context.Background())
	_ = manager.StopSocks(context.Background())
}()

resp, err := http.Get("http://" + manager.ForwardAddr() + "/healthz")
if err != nil {
	panic(err)
}
defer resp.Body.Close()

fmt.Println(resp.StatusCode)
fmt.Println(manager.SocksAddr() != "")
Output:
200
true

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyConfig

type ApplyConfig struct {
	ForwardEnabled bool
	ForwardAddr    string

	SocksEnabled  bool
	SocksAddr     string
	SocksAuthMode string
	SocksUser     string
	SocksPass     string
}

ApplyConfig enables or restarts listeners according to the provided configuration.

type Manager

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

Manager manages separate listeners for forward-proxy and SOCKS5. Listener restarts are graceful via Shutdown/Close.

func New

func New(log *zerolog.Logger) *Manager

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, cfg ApplyConfig, forwardHandler http.Handler) error

Apply accepts a handler for forward-proxy.

func (*Manager) ForwardAddr

func (m *Manager) ForwardAddr() string

ForwardAddr returns the actual forward-proxy address if running.

func (*Manager) SocksAddr

func (m *Manager) SocksAddr() string

SocksAddr returns the actual SOCKS5 address if running.

func (*Manager) StartForward

func (m *Manager) StartForward(addr string, handler http.Handler) error

StartForward starts an HTTP server on addr with the provided handler.

func (*Manager) StartSocks

func (m *Manager) StartSocks(addr, authMode, user, pass string) error

StartSocks starts a SOCKS5 server on addr with optional authentication. authMode: "none" | "userpass"; user/pass are only used for userpass.

func (*Manager) StopForward

func (m *Manager) StopForward(ctx context.Context) error

func (*Manager) StopSocks

func (m *Manager) StopSocks(ctx context.Context) error

Jump to

Keyboard shortcuts

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