context

package
v2.7.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Overview

Package context provides the context for traffic handlers.

Index

Constants

View Source
const (
	EGStatusContinue              = http.StatusContinue
	EGStatusSwitchingProtocols    = http.StatusSwitchingProtocols
	EGStatusProcessing            = http.StatusProcessing
	EGStatusOK                    = http.StatusOK
	EGStatusCreated               = http.StatusCreated
	EGStatusAccepted              = http.StatusAccepted
	EGStatusNoContent             = http.StatusNoContent
	EGStatusPartialContent        = http.StatusPartialContent
	EGStatusSpecialResponse       = 300 // http.StatusMultipleChoices
	EGStatusMovedPermanently      = http.StatusMovedPermanently
	EGStatusMovedTemporarily      = 302 // http.StatusFound
	EGStatusSeeOther              = http.StatusSeeOther
	EGStatusNotModified           = http.StatusNotModified
	EGStatusTemporaryRedirect     = http.StatusTemporaryRedirect
	EGStatusBadRequest            = http.StatusBadRequest
	EGStatusUnauthorized          = http.StatusUnauthorized
	EGStatusForbidden             = http.StatusForbidden
	EGStatusNotFound              = http.StatusNotFound
	EGStatusNotAllowed            = http.StatusMethodNotAllowed
	EGStatusRequestTimeOut        = http.StatusRequestTimeout
	EGStatusConflict              = http.StatusConflict
	EGStatusLengthRequired        = http.StatusLengthRequired
	EGStatusPreconditionFailed    = http.StatusPreconditionFailed
	EGStatusRequestEntityTooLarge = http.StatusRequestEntityTooLarge
	EGStatusRequestURITooLong     = http.StatusRequestURITooLong
	EGStatusUnsupportedMediaType  = http.StatusUnsupportedMediaType
	EGStatusRangeNotSatisfiable   = http.StatusRequestedRangeNotSatisfiable
	EGStatusTooManyRequests       = http.StatusTooManyRequests
	EGStatusClose                 = 444
	EGStatusEgCodes               = 494
	EGStatusRequestHeaderTooLarge = 494
	EGStatusHTTPSCertError        = 495
	EGStatusHTTPSNoCert           = 496
	EGStatusToHTTPS               = 497
	EGStatusClientClosedRequest   = 499
	EGStatusInternalServerError   = http.StatusInternalServerError
	EGStatusNotImplemented        = http.StatusNotImplemented
	EGStatusBadGateway            = http.StatusBadGateway
	EGStatusServiceUnavailable    = http.StatusServiceUnavailable
	EGStatusGatewayTimeOut        = http.StatusGatewayTimeout
	EGStatusInsufficientStorage   = http.StatusInsufficientStorage
	EGStatusBadResponse           = 599
)

the error code list which align with the HTTP status code

View Source
const DefaultNamespace = "DEFAULT"

DefaultNamespace is the name of the default namespace.

Variables

This section is empty.

Functions

func IsNetworkError

func IsNetworkError(code int) bool

IsNetworkError returns if the error is network type.

Types

type Context

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

Context holds requests, responses and other data that need to be passed through the pipeline.

func New

func New(span *tracing.Span) *Context

New creates a new Context.

func (*Context) AddTag

func (ctx *Context) AddTag(tag string)

AddTag add a tag to the Context.

func (*Context) CopyRequest

func (ctx *Context) CopyRequest(ns string)

CopyRequest copies the request of namespace ns to the active namespace. The copied request is a new reference of the original request, that's they both point to the same underlying protocols.Request.

func (*Context) CopyResponse

func (ctx *Context) CopyResponse(ns string)

CopyResponse copies the response of namespace ns to the active namespace. The copied response is a new reference of the original response, that's they both point to the same underlying protocols.Response.

func (*Context) Data

func (ctx *Context) Data() map[string]interface{}

Data returns all data that stored in the context.

func (*Context) Finish

func (ctx *Context) Finish()

Finish calls all finish functions.

func (*Context) GetData

func (ctx *Context) GetData(key string) interface{}

GetData returns the data of key.

func (*Context) GetInputRequest

func (ctx *Context) GetInputRequest() protocols.Request

GetInputRequest returns the request of the input namespace.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call GetOutputRequest when GetInputRequest is desired, or vice versa.

func (*Context) GetInputResponse

func (ctx *Context) GetInputResponse() protocols.Response

GetInputResponse returns the response of the input namespace.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call GetOutputResponse when GetInputResponse is desired, or vice versa.

func (*Context) GetOutputRequest

func (ctx *Context) GetOutputRequest() protocols.Request

GetOutputRequest returns the request of the output namespace.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call GetInputRequest when GetOutputRequest is desired, or vice versa.

func (*Context) GetOutputResponse

func (ctx *Context) GetOutputResponse() protocols.Response

GetOutputResponse returns the response of the output namespace.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call GetInputResponse when GetOutputResponse is desired, or vice versa.

func (*Context) GetRequest

func (ctx *Context) GetRequest(ns string) protocols.Request

GetRequest set the request of namespace ns to req.

func (*Context) GetResponse

func (ctx *Context) GetResponse(ns string) protocols.Response

GetResponse returns the response of namespace ns.

func (*Context) GetRoute added in v2.6.3

func (ctx *Context) GetRoute() (protocols.Route, bool)

GetRoute returns the route with the existing flag.

func (*Context) LazyAddTag

func (ctx *Context) LazyAddTag(lazyTagFunc func() string)

LazyAddTag add a tag to the Context in a lazy fashion.

func (*Context) Namespace

func (ctx *Context) Namespace() string

Namespace returns the active namespace.

func (*Context) OnFinish

func (ctx *Context) OnFinish(fn func())

OnFinish registers a function to be called in Finish.

func (*Context) Requests

func (ctx *Context) Requests() map[string]protocols.Request

Requests returns all requests, the caller should NOT modify the return value.

func (*Context) Responses

func (ctx *Context) Responses() map[string]protocols.Response

Responses returns all responses.

func (*Context) SetData

func (ctx *Context) SetData(key string, val interface{})

SetData sets the data of key to val.

func (*Context) SetInputRequest

func (ctx *Context) SetInputRequest(req protocols.Request)

SetInputRequest sets the request of the input namespace to req.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call SetOutputRequest when SetInputRequest is desired, or vice versa.

func (*Context) SetInputResponse

func (ctx *Context) SetInputResponse(resp protocols.Response)

SetInputResponse sets the response of the input namespace to resp.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call SetOutputResponse when SetInputResponse is desired, or vice versa.

func (*Context) SetOutputRequest

func (ctx *Context) SetOutputRequest(req protocols.Request)

SetOutputRequest sets the request of the output namespace to req.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call SetInputRequest when SetOutputRequest is desired, or vice versa.

func (*Context) SetOutputResponse

func (ctx *Context) SetOutputResponse(resp protocols.Response)

SetOutputResponse sets the response of the output namespace to resp.

Currently, the output namespace is the same as the input namespace, but this may change in the future, code calling this function should be ready for the change and not to call SetInputResponse when SetOutputResponse is desired, or vice versa.

func (*Context) SetRequest

func (ctx *Context) SetRequest(ns string, req protocols.Request)

SetRequest set the request of namespace ns to req.

func (*Context) SetResponse

func (ctx *Context) SetResponse(ns string, resp protocols.Response)

SetResponse set the response of namespace ns to resp.

func (*Context) SetRoute added in v2.6.3

func (ctx *Context) SetRoute(route protocols.Route)

SetRoute sets the route.

func (*Context) Span

func (ctx *Context) Span() *tracing.Span

Span returns the span of this Context.

func (*Context) Tags

func (ctx *Context) Tags() string

Tags joins all tags into a string and returns it.

func (*Context) UseNamespace

func (ctx *Context) UseNamespace(ns string)

UseNamespace sets the active namespace.

type Handler

type Handler interface {
	Handle(ctx *Context) string
}

Handler is the common interface for all traffic handlers, which handle the traffic represented by ctx.

type MuxMapper

type MuxMapper interface {
	GetHandler(name string) (Handler, bool)
}

MuxMapper gets the traffic handler by name.

Directories

Path Synopsis
Package contexttest provides utilities for testing context.
Package contexttest provides utilities for testing context.

Jump to

Keyboard shortcuts

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