Documentation
¶
Index ¶
- func DefaultBalancer() balancer.Builder
- func GetBalancer(name string) balancer.Builder
- func RegisterBalancer(b balancer.Builder)
- type Context
- func (c *Context) Abort()
- func (c *Context) AbortWithJSON(code int, obj interface{})
- func (c *Context) AbortWithStatus(code int)
- func (c *Context) Get(key string) (value interface{}, exists bool)
- func (c *Context) IsAborted() bool
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) Next()
- func (c *Context) Render(code int, r Render)
- func (c *Context) Route() *Route
- func (c *Context) Set(key string, value interface{})
- func (c *Context) Status(code int)
- func (c *Context) String(code int, s string)
- func (c *Context) Target() *url.URL
- type Engine
- func (this *Engine) HandleError(handler ErrorHandler)
- func (this *Engine) Load(provider RouteProvider)
- func (this *Engine) NoProxy(handlers ...HandlerFunc)
- func (this *Engine) NoRoute(handlers ...HandlerFunc)
- func (this *Engine) ServeHTTP(writer http.ResponseWriter, request *http.Request)
- func (this *Engine) Use(middleware ...HandlerFunc)
- type ErrorHandler
- type HandlerFunc
- type HandlersChain
- type ListProvider
- type Option
- type ProxyBuilder
- type Render
- type ResponseWriter
- type Route
- type RouteProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultBalancer ¶
func GetBalancer ¶
func RegisterBalancer ¶
Types ¶
type Context ¶
type Context struct {
Request *http.Request
Writer ResponseWriter
Keys map[string]interface{}
// contains filtered or unexported fields
}
func (*Context) AbortWithJSON ¶
func (*Context) AbortWithStatus ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
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 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"})
type Option ¶
type Option func(opts *options)
func WithBalancer ¶
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 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 ...
Source Files
¶
Click to show internal directories.
Click to hide internal directories.