forward

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorHandler added in v0.12.0

type ErrorHandler func(err error)

ErrorHandler 处理转发过程中的异步错误

type Option added in v0.12.0

type Option func(c *config)

Option 用于配置 TCPForwarder 和 UDPForwarder

func WithErrorHandler added in v0.12.0

func WithErrorHandler(h ErrorHandler) Option

WithErrorHandler 允许调用方注入异步错误处理回调(必须支持并发调用)

func WithLogger added in v0.12.0

func WithLogger(l logger.DebugLogger) Option

WithLogger 允许调用方注入 DebugLogger 实现(必须支持并发调用)

type TCPForwarder

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

TCPForwarder listens on a local TCP address and forwards connections to a target address.

func NewTCPForwarder

func NewTCPForwarder(listenAddr, targetAddr string, opts ...Option) *TCPForwarder

NewTCPForwarder creates a new TCPForwarder.

func (*TCPForwarder) Run

func (f *TCPForwarder) Run(ctx context.Context) (err error)

Run starts the TCP forwarder and blocks until ctx is canceled. It does not return until every accepted connection handler has exited.

type UDPForwarder

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

UDPForwarder listens on a local UDP address and forwards datagrams to a target address.

func NewUDPForwarder

func NewUDPForwarder(listenAddr, targetAddr string, opts ...Option) *UDPForwarder

NewUDPForwarder creates a new UDPForwarder.

func (*UDPForwarder) Run

func (f *UDPForwarder) Run(ctx context.Context) (err error)

Run starts the UDP forwarder and blocks until ctx is canceled. It closes all sessions and waits for every forwarding goroutine before returning.

Jump to

Keyboard shortcuts

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