rx

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBalancer

func DefaultBalancer() balancer.Builder

func GetBalancer

func GetBalancer(name string) balancer.Builder

func RegisterBalancer

func RegisterBalancer(b balancer.Builder)

Types

type Context

type Context struct {
	Request *http.Request
	Writer  ResponseWriter

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

func (*Context) Abort

func (c *Context) Abort()

func (*Context) AbortWithJSON

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

func (*Context) AbortWithStatus

func (c *Context) AbortWithStatus(code int)

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) 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)

func (*Context) Target

func (c *Context) Target() *url.URL

type Engine

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

func New

func New() *Engine

func (*Engine) HandleError

func (this *Engine) HandleError(handler ErrorHandler)

func (*Engine) Load

func (this *Engine) Load(provider RouteProvider)

func (*Engine) NoProxy

func (this *Engine) NoProxy(handlers ...HandlerFunc)

func (*Engine) NoRoute

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

func (*Engine) ServeHTTP

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

func (*Engine) Use

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

type ErrorHandler

type ErrorHandler func(c *Context, err error)

type HandlerFunc

type HandlerFunc func(c *Context)

type HandlersChain

type HandlersChain []HandlerFunc

type ListProvider

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

ListProvider 路由信息管理

内部维护了一个 Route 对象的切片,可用于路由规则较少的场景。

func NewListProvider

func NewListProvider() *ListProvider

func (*ListProvider) Add

func (this *ListProvider) Add(pattern string, targets []string, opts ...Option) error

Add 添加路由规则

由于 ListProvider 的 Match 方法是依次对路由进行匹配,所以规则 /user 应该先于规则 /u 添加。

如:

provider.Add("/user", []string{"http://xxx"})

provider.Add("/u", []string{"http://xxx"})

func (*ListProvider) Match

func (this *ListProvider) Match(req *http.Request) (*Route, error)

Match 匹配路由

type Option

type Option func(opts *options)

func WithBalancer

func WithBalancer(name string) Option

func WithHandlers

func WithHandlers(handlers ...HandlerFunc) Option

func WithProxyBuilder

func WithProxyBuilder(builder ProxyBuilder) Option

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 struct {
	// contains filtered or unexported fields
}

func NewRoute

func NewRoute(pattern string, targets []string, opts ...Option) (*Route, error)

func (*Route) Match

func (this *Route) Match(path string) bool

func (*Route) Pattern

func (this *Route) Pattern() string

type RouteProvider

type RouteProvider interface {
	Match(req *http.Request) (*Route, error)
}

Directories

Path Synopsis
examples module

Jump to

Keyboard shortcuts

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