Documentation
¶
Overview ¶
Package core provides some core runtime functions.
Index ¶
- Variables
- func CopyResponse(c *Context, resp *http.Response)
- func CopyResponseHeader(c *Context, resp *http.Response)
- func ReleaseContext(c *Context)
- func StdResponse(c *Context, resp *http.Response, err error)
- type Context
- func (c *Context) Abort(err error)
- func (c *Context) CallbackOnForward()
- func (c *Context) CallbackOnResponseHeader()
- func (c *Context) ClientIP() netip.Addr
- func (c *Context) Cookie(name string) string
- func (c *Context) Cookies() []*http.Cookie
- func (c *Context) OnForward(cb func())
- func (c *Context) OnResponseHeader(cb func())
- func (c *Context) Queries() url.Values
- func (c *Context) RemoteAddr() string
- func (c *Context) RequestID() string
- func (c *Context) Reset()
- func (c *Context) SendResponse()
- type Handler
- type ResponseWriter
- type Responser
- type ResponserFunc
Constants ¶
This section is empty.
Variables ¶
var ( // AcquireResponseWriter is used to customize the wrapper // from http.ResponseWriter to ResponseWriter. AcquireResponseWriter func(http.ResponseWriter) ResponseWriter = acquireResponseWriter // ReleaseResponseWriter is used to release the response writer // acquired by AcquireResponseWriter. ReleaseResponseWriter func(ResponseWriter) = releaseResponseWriter )
var DefaultCapSize = 4
Functions ¶
func CopyResponse ¶
CopyResponse copies the response header and body from the upstream server to the client.
func CopyResponseHeader ¶
CopyResponseHeader copies the response header from the upstream server to the client.
func ReleaseContext ¶
func ReleaseContext(c *Context)
ReleaseContext releases the context to the pool.
Types ¶
type Context ¶
type Context struct { Context context.Context Next Handler RouteId string // Set by the router after matching the route. UpstreamId string // Set by the router after matching the route. // For Client Client *http.Client ClientRequest *http.Request // Set by the router when serving the request. ClientResponse ResponseWriter // Set by the router when serving the request. Responser Responser // Set by the router after matching the route. // For Upstream Upstream interface{} UpstreamRequest *http.Request UpstreamResponse *http.Response // Set by the upstream after forwarding the request. ForwardTimeout time.Duration Endpoint loadbalancer.Endpoint // Set by the endpoint IsAborted bool Error error // Set when aborting the context process anytime. Data interface{} // The contex data that is set and used by the final user. Kvs map[string]any // The interim context key-value cache. // contains filtered or unexported fields }
Context represents a runtime context.
func AcquireContext ¶
AcquireContext acquires a context from the pool.
func NewContext ¶
func NewContext() *Context
func (*Context) CallbackOnForward ¶
func (c *Context) CallbackOnForward()
CallbackOnForward calls the callback functions added by OnForward.
func (*Context) CallbackOnResponseHeader ¶
func (c *Context) CallbackOnResponseHeader()
CallbackOnResponseHeader calls the callback functions added by OnResponseHeader.
func (*Context) OnForward ¶
func (c *Context) OnForward(cb func())
OnForward appends the callback function, which is called before upstream forwards the request.
func (*Context) OnResponseHeader ¶
func (c *Context) OnResponseHeader(cb func())
OnResponseHeader appends the callback function, which is called after setting the response header and before copying the response body from the upstream server to the client.
func (*Context) RemoteAddr ¶
RemoteAddr returns the remote address of the request.
func (*Context) SendResponse ¶
func (c *Context) SendResponse()
SendResponse sends the response from the upstream server to the client.
type ResponseWriter ¶
type ResponseWriter interface { http.ResponseWriter WroteHeader() bool StatusCode() int }
ResponseWriter is the extension of http.ResponseWriter.