Documentation
¶
Index ¶
- Constants
- Variables
- func Debug(args ...any)
- func Debugf(format string, args ...any)
- func Error(args ...any)
- func Errorf(format string, args ...any)
- func Fatal(args ...any)
- func Fatalf(format string, args ...any)
- func Info(args ...any)
- func Infof(format string, args ...any)
- func IsDomain(hostname string) bool
- func ListenAndServe(network, addr string, cfg *Config) error
- func Panic(args ...any)
- func Panicf(format string, args ...any)
- func Serve(inner net.Listener, cfg *Config) error
- func SetLogLevel(level Level)
- func Trace(args ...any)
- func Tracef(format string, args ...any)
- func Warn(args ...any)
- func Warnf(format string, args ...any)
- type Config
- func (c *Config) WithOptions(opts ...ConfigOption) *Config
- func (c *Config) WithRawMatcher(matcher ...RawMatcher) *RawFilter
- func (c *Config) WithReqMatcher(matcher ...ReqMatcher) *ReqFilter
- func (c *Config) WithRespMatcher(matcher ...RespMatcher) *RespFilter
- func (c *Config) WithWsMatcher(matcher ...WsMatcher) *WsFilter
- type ConfigOption
- func WithDialer(dialer Dialer) ConfigOption
- func WithDispatcher(dispatcher Dispatcher) ConfigOption
- func WithHttpHandler(httpHandler HttpHandler) ConfigOption
- func WithLimiter(limiter Limiter) ConfigOption
- func WithNegotiator(negotiator Negotiator) ConfigOption
- func WithTLSConfigFn(tlsConfig TLSConfig) ConfigOption
- func WithTcpHandler(tcpHandler TcpHandler) ConfigOption
- func WithWsHandler(wsHandler WsHandler) ConfigOption
- type Conn
- type Context
- func (c *Context) Debug(args ...any)
- func (c *Context) Debugf(format string, args ...any)
- func (c *Context) Error(args ...any)
- func (c *Context) Errorf(format string, args ...any)
- func (c *Context) Fatal(args ...any)
- func (c *Context) Fatalf(format string, args ...any)
- func (c *Context) Info(args ...any)
- func (c *Context) Infof(format string, args ...any)
- func (c *Context) Panic(args ...any)
- func (c *Context) Panicf(format string, args ...any)
- func (c *Context) SetLogLevel(level Level)
- func (c *Context) SetLogger(logger Logger)
- func (c *Context) Trace(args ...any)
- func (c *Context) Tracef(format string, args ...any)
- func (c *Context) Warn(args ...any)
- func (c *Context) Warnf(format string, args ...any)
- type Dialer
- type DialerOption
- type DispatchFn
- type Dispatcher
- type HandleHttpFn
- type HandleTcpFn
- type HandleWsFn
- type HandshakeFn
- type HttpHandler
- type Level
- type Limiter
- type Listener
- type Logger
- type Logrus
- type Negotiator
- type RawFilter
- type RawHandlerFn
- type RawMatchFn
- type RawMatcher
- type ReqFilter
- type ReqHandlerFn
- type ReqMatchFn
- type ReqMatcher
- type Resolver
- type RespFilter
- type RespHandlerFn
- type RespMatchFn
- type RespMatcher
- type StdLimiter
- type StdResolver
- type TLSConfig
- type TLSConfigFn
- type TcpHandler
- type WsFilter
- type WsHandler
- type WsHandlerFn
- type WsMatchFn
- type WsMatcher
Constants ¶
const CertificatePEM = `` /* 1536-byte string literal not displayed */
const PrivateKeyPEM = `` /* 1674-byte string literal not displayed */
Variables ¶
var Certificate *x509.Certificate
var HttpMethods = map[string]struct{}{ http.MethodGet[:3]: {}, http.MethodHead[:3]: {}, http.MethodPost[:3]: {}, http.MethodPut[:3]: {}, http.MethodPatch[:3]: {}, http.MethodConnect[:3]: {}, http.MethodDelete[:3]: {}, http.MethodOptions[:3]: {}, http.MethodTrace[:3]: {}, }
var PrivateKey *rsa.PrivateKey
Functions ¶
func ListenAndServe ¶
func SetLogLevel ¶
func SetLogLevel(level Level)
Types ¶
type Config ¶
type Config struct {
Negotiator Negotiator
Resolver Resolver
Dispatcher Dispatcher
TLSConfig TLSConfig
HttpHandler HttpHandler
WsHandler WsHandler
TcpHandler TcpHandler
DefaultSAN string
// contains filtered or unexported fields
}
func (*Config) WithOptions ¶
func (c *Config) WithOptions(opts ...ConfigOption) *Config
func (*Config) WithRawMatcher ¶
func (c *Config) WithRawMatcher(matcher ...RawMatcher) *RawFilter
func (*Config) WithReqMatcher ¶
func (c *Config) WithReqMatcher(matcher ...ReqMatcher) *ReqFilter
func (*Config) WithRespMatcher ¶
func (c *Config) WithRespMatcher(matcher ...RespMatcher) *RespFilter
func (*Config) WithWsMatcher ¶
type ConfigOption ¶
type ConfigOption func(*Config)
func WithDialer ¶
func WithDialer(dialer Dialer) ConfigOption
func WithDispatcher ¶
func WithDispatcher(dispatcher Dispatcher) ConfigOption
func WithHttpHandler ¶
func WithHttpHandler(httpHandler HttpHandler) ConfigOption
func WithLimiter ¶
func WithLimiter(limiter Limiter) ConfigOption
func WithNegotiator ¶
func WithNegotiator(negotiator Negotiator) ConfigOption
func WithTLSConfigFn ¶
func WithTLSConfigFn(tlsConfig TLSConfig) ConfigOption
func WithTcpHandler ¶
func WithTcpHandler(tcpHandler TcpHandler) ConfigOption
func WithWsHandler ¶
func WithWsHandler(wsHandler WsHandler) ConfigOption
type Context ¶
type Context struct {
context.Context
Id string
Conn *Conn
*Config
DstHost string
DstPort string
Req *http.Request
// contains filtered or unexported fields
}
func NewContext ¶
func NewContext() *Context
func (*Context) SetLogLevel ¶
type Dialer ¶
type Dialer interface {
Dial(string, string, ...DialerOption) (net.Conn, error)
WithOptions(...DialerOption) Dialer
}
type DialerOption ¶
type DialerOption func(*dialerConfig)
func WithTLSConfig ¶
func WithTLSConfig(cfg *tls.Config) DialerOption
type DispatchFn ¶
type DispatchFn func(*Context)
func (DispatchFn) Dispatch ¶
func (f DispatchFn) Dispatch(ctx *Context)
type Dispatcher ¶
type Dispatcher interface {
Dispatch(*Context)
}
type HandleHttpFn ¶
type HandleHttpFn func(*Context)
func (HandleHttpFn) HandleHttp ¶
func (f HandleHttpFn) HandleHttp(ctx *Context)
type HandleTcpFn ¶
type HandleTcpFn func(*Context)
func (HandleTcpFn) HandleTcp ¶
func (f HandleTcpFn) HandleTcp(ctx *Context)
type HandleWsFn ¶
type HandleWsFn func(*Context)
HandleWsFn is a function type adapter that implements the WsHandler interface. HandleWsFn 是一个函数类型适配器,用于实现 WsHandler 接口。
func (HandleWsFn) HandleWs ¶
func (f HandleWsFn) HandleWs(ctx *Context)
HandleWs calls the function itself to handle the WebSocket request. HandleWs 会直接调用函数本身来处理 WebSocket 请求。
type HandshakeFn ¶
HandshakeFn is a function adapter that implements the Negotiator interface. HandshakeFn 是一个实现 Negotiator 接口的函数适配器。
var Socks5Negotiator HandshakeFn = func(ctx *Context) error { return socks5Handshake(ctx) }
Socks5Negotiator is a built-in SOCKS5 handshake handler. Socks5Negotiator 是内置的 SOCKS5 握手处理器。
func (HandshakeFn) Handshake ¶
func (f HandshakeFn) Handshake(ctx *Context) error
Handshake calls the function itself. Handshake 方法直接调用函数本体。
type HttpHandler ¶
type HttpHandler interface {
HandleHttp(*Context)
}
type Negotiator ¶
Negotiator defines the handshake behavior for various protocols. Negotiator 接口定义了各种协议的握手行为。
type RawFilter ¶
type RawFilter struct {
// contains filtered or unexported fields
}
func (*RawFilter) Handle ¶ added in v1.3.0
func (r *RawFilter) Handle(handle RawHandlerFn)
type RawHandlerFn ¶
type RawMatchFn ¶
func RawHostIs ¶
func RawHostIs(hosts ...string) RawMatchFn
type RawMatcher ¶
type ReqFilter ¶
type ReqFilter struct {
// contains filtered or unexported fields
}
func (*ReqFilter) Handle ¶
func (r *ReqFilter) Handle(handle ReqHandlerFn)
type ReqMatchFn ¶
func Not ¶
func Not(matcher ReqMatcher) ReqMatchFn
func ReqHostIs ¶
func ReqHostIs(hosts ...string) ReqMatchFn
type ReqMatcher ¶
type ReqMatcher interface {
MatchReq(*http.Request, *Context) bool
RespMatcher
}
type Resolver ¶
func NewResolver ¶
func NewResolver() Resolver
type RespFilter ¶
type RespFilter struct {
// contains filtered or unexported fields
}
func (*RespFilter) Handle ¶
func (r *RespFilter) Handle(handle RespHandlerFn)
type RespMatchFn ¶
func StatusCodeIs ¶
func StatusCodeIs(codes ...int) RespMatchFn
type StdLimiter ¶ added in v1.3.1
func (*StdLimiter) Acquire ¶ added in v1.3.1
func (l *StdLimiter) Acquire()
func (*StdLimiter) Release ¶ added in v1.3.1
func (l *StdLimiter) Release()
type StdResolver ¶ added in v1.3.4
func (StdResolver) PTRSet ¶ added in v1.3.4
func (r StdResolver) PTRSet(ip string, domain string)
type TLSConfig ¶
TLSConfig defines an interface for dynamically generating a *tls.Config based on the provided Server Name (SAN). TLSConfig 定义了一个接口,用于根据传入的服务名称(SAN)动态生成 *tls.Config。
type TLSConfigFn ¶
TLSConfigFn is a function adapter that implements the TLSConfig interface. TLSConfigFn 是一个函数适配器,实现了 TLSConfig 接口。
func From ¶
func From(cert *x509.Certificate, privateKey crypto.PrivateKey) TLSConfigFn
From returns a static tls.Config using the given certificate and private key. From 使用传入的证书和私钥构造并返回一个固定的 tls.Config。
func FromCA ¶
func FromCA(cert *x509.Certificate, privateKey *rsa.PrivateKey) TLSConfigFn
FromCA creates a TLSConfigFn using a CA certificate and private key, which generates leaf certificates signed by the CA for the specified SAN. FromCA 使用 CA 证书和私钥返回一个 TLSConfigFn, 会为指定的 SAN 签发由 CA 签名的服务端证书。
func FromSelfSigned ¶
func FromSelfSigned() TLSConfigFn
FromSelfSigned generates a self-signed certificate for the given SAN and returns a tls.Config containing that certificate. FromSelfSigned 会为指定 SAN 创建一个自签名证书,并返回包含该证书的 tls.Config。
type TcpHandler ¶
type TcpHandler interface {
HandleTcp(*Context)
}
type WsFilter ¶
type WsFilter struct {
// contains filtered or unexported fields
}
func (*WsFilter) Handle ¶
func (w *WsFilter) Handle(handle WsHandlerFn)
type WsHandler ¶
type WsHandler interface {
HandleWs(*Context)
}
WsHandler defines the interface for handling WebSocket requests. WsHandler 定义了处理 WebSocket 请求的接口。