http

package
v0.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HttpRouteActionMatch

func HttpRouteActionMatch(c *HttpContext, ra model.RouteAction) bool

HttpRouteActionMatch

func HttpRouteMatch

func HttpRouteMatch(c *HttpContext, rm model.RouterMatch) bool

HttpRouteMatch

Types

type ErrResponse

type ErrResponse struct {
	Message string `json:"message"`
}

ErrResponse err response.

type FilterChain

type FilterChain []FilterFunc

FilterChain filter chain

type FilterFunc

type FilterFunc func(c *HttpContext)

FilterFunc filter func, filter

type HttpContext

type HttpContext struct {
	Index   int8
	Filters FilterChain
	Timeout time.Duration
	Ctx     context.Context

	// the response context will return.
	TargetResp *client.Response
	// client call response.
	SourceResp interface{}
	// happen error
	Err error

	HttpConnectionManager model.HttpConnectionManagerConfig
	Listener              *model.Listener
	Route                 *model.RouteAction
	Api                   *router.API

	Request *http.Request

	Writer ResponseWriter
	// contains filtered or unexported fields
}

HttpContext http context

func (*HttpContext) API

func (hc *HttpContext) API(api router.API)

API sets the API to http context

func (*HttpContext) Abort

func (hc *HttpContext) Abort()

Abort filter chain break , filter after the current filter will not executed.

func (*HttpContext) AbortWithError

func (hc *HttpContext) AbortWithError(message string, err error)

AbortWithError filter chain break , filter after the current filter will not executed. And log will print.

func (*HttpContext) AddHeader

func (hc *HttpContext) AddHeader(k, v string)

AddHeader add header

func (*HttpContext) AllHeaders

func (hc *HttpContext) AllHeaders() http.Header

AllHeaders get all headers

func (*HttpContext) AppendFilterFunc

func (hc *HttpContext) AppendFilterFunc(ff ...FilterFunc)

AppendFilterFunc append filter func.

func (*HttpContext) GetAPI

func (hc *HttpContext) GetAPI() *router.API

GetAPI get api

func (*HttpContext) GetApplicationName

func (hc *HttpContext) GetApplicationName() string

GetApplicationName get application name

func (*HttpContext) GetClientIP

func (hc *HttpContext) GetClientIP() string

GetClientIP get client IP

func (*HttpContext) GetHeader

func (hc *HttpContext) GetHeader(k string) string

GetHeader get header

func (*HttpContext) GetMethod

func (hc *HttpContext) GetMethod() string

GetMethod get method, POST/GET ...

func (*HttpContext) GetRouteEntry

func (hc *HttpContext) GetRouteEntry() *model.RouteAction

GetRouteEntry get route

func (*HttpContext) GetUrl

func (hc *HttpContext) GetUrl() string

GetUrl get http request url

func (*HttpContext) Next

func (hc *HttpContext) Next()

Next logic for lookup filter

func (*HttpContext) Reset

func (hc *HttpContext) Reset()

Reset reset http context

func (*HttpContext) ResetWritermen

func (hc *HttpContext) ResetWritermen(w http.ResponseWriter)

ResetWritermen reset writermen

func (*HttpContext) RouteEntry

func (hc *HttpContext) RouteEntry(r *model.RouteAction)

RouteEntry set route

func (*HttpContext) SetUrl

func (hc *HttpContext) SetUrl(url string)

func (*HttpContext) Status

func (hc *HttpContext) Status(code int)

Status set header status code

func (*HttpContext) StatusCode

func (hc *HttpContext) StatusCode() int

StatusCode get header status code

func (*HttpContext) Write

func (hc *HttpContext) Write(b []byte) (int, error)

Write write body data

func (*HttpContext) WriteErr

func (hc *HttpContext) WriteErr(p interface{})

WriteErr

func (*HttpContext) WriteHeaderNow

func (hc *HttpContext) WriteHeaderNow()

WriteHeaderNow write header now

func (*HttpContext) WriteJSONWithStatus

func (hc *HttpContext) WriteJSONWithStatus(code int, res interface{})

WriteJSONWithStatus write fail, auto add context-type json.

func (*HttpContext) WriteResponse

func (hc *HttpContext) WriteResponse(resp client.Response)

WriteResponse

func (*HttpContext) WriteSuccess

func (hc *HttpContext) WriteSuccess()

WriteSuccess

func (*HttpContext) WriteWithStatus

func (hc *HttpContext) WriteWithStatus(code int, b []byte) (int, error)

WriteWithStatus status must set first

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter
	http.Hijacker
	http.Flusher
	// todo replace it later version
	// nolint
	http.CloseNotifier

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

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

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

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

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

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

ResponseWriter ...

Jump to

Keyboard shortcuts

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