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 ¶
- type ApplyConfig
- type Manager
- func (m *Manager) Apply(ctx context.Context, cfg ApplyConfig, forwardHandler http.Handler) error
- func (m *Manager) ForwardAddr() string
- func (m *Manager) SocksAddr() string
- func (m *Manager) StartForward(addr string, handler http.Handler) error
- func (m *Manager) StartSocks(addr, authMode, user, pass string) error
- func (m *Manager) StopForward(ctx context.Context) error
- func (m *Manager) StopSocks(ctx context.Context) error
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 (*Manager) ForwardAddr ¶
ForwardAddr returns the actual forward-proxy address if running.
func (*Manager) StartForward ¶
StartForward starts an HTTP server on addr with the provided handler.
func (*Manager) StartSocks ¶
StartSocks starts a SOCKS5 server on addr with optional authentication. authMode: "none" | "userpass"; user/pass are only used for userpass.