context

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HttpContext

type HttpContext struct {
	Request          *HttpRequest
	Response         *HttpResponse
	Header           collections.ReadonlyDictionary[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) BuildActionInValue added in v0.3.0

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

BuildActionInValue 根据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
	R          *http.Request
}

func (*HttpRequest) JsonToMap

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

JsonToMap 将json转成map类型

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
	W          http.ResponseWriter
	StatusCode int
}

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              collections.List[string]       // method
	ParamNames          collections.List[string]       // 入参变量名称
	RequestParamIsModel bool                           // 是否为DTO结构
	ResponseBodyIsModel bool                           // 是否为DTO结构
	AutoBindHeaderName  string                         // 自动绑定header的字段名称
	IsImplActionFilter  bool                           // 是否实现了IActionFilter
	IsGoBasicType       bool                           // 返回值只有一个时,是否为基础类型
	HttpMiddleware      IMiddleware                    // 中间件入口
	HandleMiddleware    IMiddleware                    // handle中间件
}

HttpRoute 路由表

func (*HttpRoute) MapToParams added in v0.3.0

func (receiver *HttpRoute) MapToParams(mapVal map[string]any) []reflect.Value

MapToParams 将map转成入参值

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]
}

type IMiddleware added in v0.3.0

type IMiddleware interface {
	Invoke(httpContext *HttpContext)
}

IMiddleware 中间件

Jump to

Keyboard shortcuts

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