context

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LstRouteTable collections.List[HttpRoute]

Functions

This section is empty.

Types

type HttpContext

type HttpContext struct {
	Request          *HttpRequest
	Response         *HttpResponse
	Header           collections.Dictionary[string, string]
	Route            *HttpRoute
	URI              *HttpURL
	Method           string
	ContentLength    int64
	Close            bool
	TransferEncoding []string
	ContentType      string
	Exception        any
}

func NewHttpContext

func NewHttpContext(httpRoute HttpRoute, w http.ResponseWriter, r *http.Request) HttpContext

NewHttpContext 初始化上下文

func (*HttpContext) GetRequestParam

func (httpContext *HttpContext) GetRequestParam() []reflect.Value

GetRequestParam 根据method映射入参

func (*HttpContext) IsActionResult

func (httpContext *HttpContext) IsActionResult() bool

IsActionResult 是否为ActionResult类型

type HttpRequest

type HttpRequest struct {
	Body       io.ReadCloser
	BodyString string
	BodyBytes  []byte
	Form       map[string]any
	Query      map[string]any
}

func (*HttpRequest) JsonToMap

func (r *HttpRequest) JsonToMap() map[string]any

func (*HttpRequest) ParseForm

func (r *HttpRequest) ParseForm()

func (*HttpRequest) ParseQuery

func (r *HttpRequest) ParseQuery(values url.Values)

type HttpResponse

type HttpResponse struct {
	Body       []reflect.Value
	BodyString string
	BodyBytes  []byte

	StatusCode int
	// contains filtered or unexported fields
}

func (HttpResponse) AddHeader

func (receiver HttpResponse) AddHeader(key, value string)

AddHeader 添加头部

func (HttpResponse) DelHeader

func (receiver HttpResponse) DelHeader(key string)

DelHeader 删除头部

func (HttpResponse) SetHeader

func (receiver HttpResponse) SetHeader(key, value string)

SetHeader 覆盖头部

func (HttpResponse) Write

func (receiver HttpResponse) Write(content []byte) (int, error)

Write 将响应内容写入http流

func (HttpResponse) WriteCode

func (receiver HttpResponse) WriteCode(statusCode int)

WriteCode 将响应状态写入http流

type HttpRoute

type HttpRoute struct {
	RouteUrl            string                         // 路由地址
	Controller          reflect.Type                   // 控制器类型
	ControllerName      string                         // 控制器名称
	Action              any                            // action类型
	ActionName          string                         // action名称
	RequestParamType    collections.List[reflect.Type] // 入参
	ResponseBodyType    collections.List[reflect.Type] // 出参
	Method              string
	ParamNames          collections.List[string]
	RequestParamIsModel bool   // 是否为DTO结构
	ResponseBodyIsModel bool   // 是否为DTO结构
	AutoBindHeaderName  string // 自动绑定header的字段名称
	IsImplActionFilter  bool   // 是否实现了IActionFilter
}

HttpRoute 路由表

type HttpURL

type HttpURL struct {
	Url         string // 请求地址
	Path        string // 请求地址
	RemoteAddr  string // 客户端IP端口
	Host        string
	Proto       string // http协议
	RequestURI  string
	QueryString string
	Query       collections.Dictionary[string, string]
}

Jump to

Keyboard shortcuts

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