rx

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2026 License: MIT Imports: 17 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProxyNotFound = errors.New("proxy not found")

Functions

func DefaultBalancer

func DefaultBalancer() balancer.Builder

func DialTLS added in v0.0.6

func DialTLS(ctx context.Context, network, addr string) (net.Conn, error)

func GetBalancer

func GetBalancer(name string) balancer.Builder

func NewReverseProxyWithTLS added in v0.0.6

func NewReverseProxyWithTLS(target *url.URL) *httputil.ReverseProxy

func RegisterBalancer

func RegisterBalancer(b balancer.Builder)

Types

type Context

type Context struct {
	Request *http.Request
	Writer  ResponseWriter
	Params  Params

	Keys map[string]interface{}
	// contains filtered or unexported fields
}

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortWithError added in v0.0.6

func (c *Context) AbortWithError(err error)

func (*Context) AbortWithJSON

func (c *Context) AbortWithJSON(code int, obj interface{})

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

func (*Context) Context added in v0.0.6

func (c *Context) Context() context.Context

func (*Context) Get

func (c *Context) Get(key string) (value interface{}, exists bool)

func (*Context) IsAborted

func (c *Context) IsAborted() bool

func (*Context) JSON

func (c *Context) JSON(code int, obj interface{})

func (*Context) Next

func (c *Context) Next()

func (*Context) Param added in v0.0.6

func (c *Context) Param(name string) string

func (*Context) Render

func (c *Context) Render(code int, r Render)

func (*Context) Route

func (c *Context) Route() Route

func (*Context) Set

func (c *Context) Set(key string, value interface{})

func (*Context) Status

func (c *Context) Status(code int)

func (*Context) String

func (c *Context) String(code int, s string)

type Engine

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

func New

func New() *Engine

func (*Engine) HandleError

func (e *Engine) HandleError(handler ErrorHandler)

func (*Engine) NoRoute

func (e *Engine) NoRoute(handlers ...HandlerFunc)

func (*Engine) ServeHTTP

func (e *Engine) ServeHTTP(writer http.ResponseWriter, request *http.Request)

func (*Engine) Use

func (e *Engine) Use(middleware ...HandlerFunc)

func (*Engine) UseRouter added in v0.0.6

func (e *Engine) UseRouter(router Router)

type ErrorHandler

type ErrorHandler func(c *Context, err error)

type HandlerFunc

type HandlerFunc func(c *Context)

func Logger added in v0.0.6

func Logger() HandlerFunc

type HandlersChain

type HandlersChain []HandlerFunc

func CombineHandlers added in v0.0.6

func CombineHandlers(base HandlersChain, handlers ...HandlerFunc) HandlersChain

type Option

type Option func(opts *options)

func WithBalancer

func WithBalancer(name string) Option

func WithProxyBuilder

func WithProxyBuilder(builder ProxyBuilder) Option

type Param added in v0.0.6

type Param struct {
	// Key 是规则中声明的参数名,不包含前缀的 : 或 *。
	Key string

	// Value 是输入路径中被该参数捕获到的原始字符串。
	Value string
}

Param 是一次路径匹配得到的单个参数。

type Params added in v0.0.6

type Params []Param

Params 是按规则中参数出现顺序保存的参数列表。

func (Params) ByName added in v0.0.6

func (ps Params) ByName(name string) string

ByName 返回指定名称的参数;不存在时返回空字符串。

func (Params) Get added in v0.0.6

func (ps Params) Get(name string) (string, bool)

Get 返回指定名称的参数。

type ProxyBuilder

type ProxyBuilder func(target *url.URL) *httputil.ReverseProxy

type Render

type Render interface {
	Render(http.ResponseWriter) error

	ContentType() []string
}

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Hijacker
	http.Flusher
	http.CloseNotifier

	// Status returns the HTTP response status code of the current request.
	Status() int

	// Size returns the number of bytes already written into the response http body.
	// See Written()
	Size() int

	// WriteString writes the string into the response body.
	WriteString(string) (int, error)

	// Written returns true if the response body was already written.
	Written() bool

	// WriteHeaderNow forces to write the http header (status code + headers).
	WriteHeaderNow()

	// Pusher get the http.Pusher for server push
	Pusher() http.Pusher
}

ResponseWriter ...

type Route

type Route interface {
	Path() string
	Handlers() HandlersChain
}

Route 表示 Router 已经匹配到的处理目标。

func NewProxyRoute added in v0.0.6

func NewProxyRoute(path string, targets []string, handlers []HandlerFunc, opts ...Option) (Route, error)

NewProxyRoute 创建反向代理路由。

func NewRoute

func NewRoute(path string, handlers ...HandlerFunc) Route

NewRoute 创建只执行本地处理函数的路由。

type Router added in v0.0.6

type Router interface {
	Match(method string, path string, params Params) (Route, Params, error)
}

Router 负责根据 method 和 path 匹配并返回 Route。

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

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