Documentation ¶
Index ¶
- Variables
- func InitJwt()
- func NewRouteRegexp(tpl string, typ RegexpType, options RouteRegexpOptions) *routeRegexp
- type HttpContext
- type HttpCookies
- func (r *HttpCookies) Get(name string) *http.Cookie
- func (r *HttpCookies) GetValue(name string) string
- func (r *HttpCookies) Remove(name string)
- func (r *HttpCookies) SetCookie(cookie *http.Cookie)
- func (r *HttpCookies) SetSuretyValue(name string, val string)
- func (r *HttpCookies) SetValue(name string, val string)
- type HttpData
- type HttpJwt
- type HttpRequest
- type HttpResponse
- func (receiver *HttpResponse) AddHeader(key, value string)
- func (receiver *HttpResponse) DelHeader(key string)
- func (receiver *HttpResponse) GetHttpCode() int
- func (receiver *HttpResponse) GetStatusCode() int
- func (receiver *HttpResponse) GetStatusMessage() string
- func (receiver *HttpResponse) Reject(httpCode int, content string)
- func (receiver *HttpResponse) SetHeader(key, value string)
- func (receiver *HttpResponse) SetHttpCode(httpCode int)
- func (receiver *HttpResponse) SetMessage(statusCode int, statusMessage string)
- func (receiver *HttpResponse) SetStatusCode(statusCode int)
- func (receiver *HttpResponse) SetValues(callValues ...reflect.Value)
- func (receiver *HttpResponse) Write(content []byte)
- func (receiver *HttpResponse) WriteJson(content any)
- func (receiver *HttpResponse) WriteString(content string)
- type HttpRoute
- type HttpURL
- type IFilter
- type IHttpSession
- type IMiddleware
- type RegexpType
- type RouteRegexpOptions
Constants ¶
This section is empty.
Variables ¶
var InvalidMessage string // key type
var InvalidStatusCode int // token无效时的状态码
Functions ¶
func NewRouteRegexp ¶ added in v0.8.0
func NewRouteRegexp(tpl string, typ RegexpType, options RouteRegexpOptions) *routeRegexp
NewRouteRegexp 构建支持正则的路由
Types ¶
type HttpContext ¶
type HttpContext struct { Request *HttpRequest // Request Response *HttpResponse // Response Header collections.ReadonlyDictionary[string, string] // 头部信息 Cookie *HttpCookies // Cookies信息 Session IHttpSession // Session信息 Route *HttpRoute // 路由信息 URI *HttpURL // URL信息 Data *HttpData // 用于传递值 Method string // 客户端提交时的Method ContentLength int64 // 客户端提交时的内容长度 ContentType string // 客户端提交时的内容类型 Exception error // 是否发生异常 Jwt *HttpJwt // jwt验证 Close bool TransferEncoding []string }
func NewHttpContext ¶
func NewHttpContext(httpRoute *HttpRoute, w http.ResponseWriter, r *http.Request) *HttpContext
NewHttpContext 初始化上下文
func (*HttpContext) IsActionResult ¶
func (receiver *HttpContext) IsActionResult() bool
IsActionResult 是否为ActionResult类型
func (*HttpContext) ParseParams ¶ added in v0.8.0
func (receiver *HttpContext) ParseParams() []reflect.Value
ParseParams 转换成Handle函数需要的参数
func (*HttpContext) RequestParamCheck ¶ added in v0.14.0
func (receiver *HttpContext) RequestParamCheck()
RequestParamCheck 实现了check.ICheck(必须放在过滤器之后执行)
type HttpCookies ¶ added in v0.8.0
type HttpCookies struct {
// contains filtered or unexported fields
}
func (*HttpCookies) Get ¶ added in v0.8.0
func (r *HttpCookies) Get(name string) *http.Cookie
Get 获取Cookie
func (*HttpCookies) GetValue ¶ added in v0.8.0
func (r *HttpCookies) GetValue(name string) string
GetValue 获取Cookie
func (*HttpCookies) Remove ¶ added in v0.8.0
func (r *HttpCookies) Remove(name string)
Remove 删除Cookie
func (*HttpCookies) SetCookie ¶ added in v0.8.0
func (r *HttpCookies) SetCookie(cookie *http.Cookie)
SetCookie 设置Cookie
func (*HttpCookies) SetSuretyValue ¶ added in v0.8.0
func (r *HttpCookies) SetSuretyValue(name string, val string)
SetSuretyValue 设置Cookie安全值,将不允许脚本读取该值(HttpOnly)
func (*HttpCookies) SetValue ¶ added in v0.8.0
func (r *HttpCookies) SetValue(name string, val string)
SetValue 设置Cookie
type HttpJwt ¶ added in v0.9.0
type HttpJwt struct {
// contains filtered or unexported fields
}
func (*HttpJwt) GetClaims ¶ added in v0.9.0
func (receiver *HttpJwt) GetClaims() jwt.MapClaims
GetClaims 读取前端提交过来的Claims
type HttpRequest ¶
type HttpResponse ¶
type HttpResponse struct { W http.ResponseWriter Body []any // Action执行的结果(Action返回值) BodyBytes []byte // 自定义输出结果 // contains filtered or unexported fields }
func (*HttpResponse) AddHeader ¶
func (receiver *HttpResponse) AddHeader(key, value string)
AddHeader 添加头部
func (*HttpResponse) GetHttpCode ¶ added in v0.9.0
func (receiver *HttpResponse) GetHttpCode() int
GetHttpCode 获取响应的HttpCode
func (*HttpResponse) GetStatusCode ¶ added in v0.9.0
func (receiver *HttpResponse) GetStatusCode() int
GetStatusCode 获取statusCode
func (*HttpResponse) GetStatusMessage ¶ added in v0.9.0
func (receiver *HttpResponse) GetStatusMessage() string
GetStatusMessage 获取statusMessage
func (*HttpResponse) Reject ¶ added in v0.9.0
func (receiver *HttpResponse) Reject(httpCode int, content string)
Reject 拒绝服务
func (*HttpResponse) SetHeader ¶
func (receiver *HttpResponse) SetHeader(key, value string)
SetHeader 覆盖头部
func (*HttpResponse) SetHttpCode ¶ added in v0.9.0
func (receiver *HttpResponse) SetHttpCode(httpCode int)
SetHttpCode 将响应状态写入http流
func (*HttpResponse) SetMessage ¶ added in v0.9.0
func (receiver *HttpResponse) SetMessage(statusCode int, statusMessage string)
SetMessage 设计响应提示信息
func (*HttpResponse) SetStatusCode ¶ added in v0.9.0
func (receiver *HttpResponse) SetStatusCode(statusCode int)
SetStatusCode 设置StatusCode
func (*HttpResponse) SetValues ¶ added in v0.9.0
func (receiver *HttpResponse) SetValues(callValues ...reflect.Value)
SetValues 设置Body值
func (*HttpResponse) WriteJson ¶ added in v0.9.0
func (receiver *HttpResponse) WriteJson(content any)
WriteJson 将响应内容转成json后写入http流
func (*HttpResponse) WriteString ¶ added in v0.9.0
func (receiver *HttpResponse) WriteString(content string)
WriteString 将响应内容写入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] // 入参变量名称(显示指定) RequestParamIsImplCheck bool // 入参DTO是否实现了Check接口 RequestParamIsModel bool // 入参是否为DTO结构 ResponseBodyIsModel bool // 出参是否为DTO结构 AutoBindHeaderName string // 自动绑定header的字段名称 IsImplActionFilter bool // 是否实现了IActionFilter IsGoBasicType bool // 返回值只有一个时,是否为基础类型 HttpMiddleware IMiddleware // 中间件入口(每个路由的管道都不一样) HandleMiddleware IMiddleware // handle中间件 RouteRegexp *routeRegexp // 正则路由 Handler http.Handler // api处理函数 Filters []IFilter // 过滤器(对单个路由的执行单元) }
HttpRoute 路由表
func (*HttpRoute) FormToParams ¶ added in v0.8.0
FormToParams 将map转成入参值
func (*HttpRoute) JsonToParams ¶ added in v0.8.0
func (receiver *HttpRoute) JsonToParams(request *HttpRequest) []reflect.Value
JsonToParams json入参转成param
type HttpURL ¶
type HttpURL struct { Url string // 请求地址 http(s)://xxx.xxx.xxx/xxx Path string // 请求地址 RemoteAddr string // 客户端IP端口 X_Forwarded_For string // 客户端IP端口 X_Real_Ip string // 客户端IP端口 Host string // 请求的Host主机头 Proto string // http协议 RequestURI string QueryString string Query map[string]any R *http.Request }
type IFilter ¶ added in v0.9.0
type IFilter interface { // OnActionExecuting 页面执行前执行 OnActionExecuting(httpContext *HttpContext) // OnActionExecuted 页面执行后执行 OnActionExecuted(httpContext *HttpContext) }
IFilter 过滤器
type IHttpSession ¶ added in v0.11.0
type IMiddleware ¶ added in v0.3.0
type IMiddleware interface {
Invoke(httpContext *HttpContext)
}
IMiddleware 中间件
type RegexpType ¶ added in v0.8.0
type RegexpType int
const ( RegexpTypePath RegexpType = iota RegexpTypeHost RegexpTypePrefix RegexpTypeQuery )