Documentation
¶
Index ¶
- Variables
- func ClearSession()
- 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 HttpRequest
- type HttpResponse
- type HttpRoute
- type HttpSession
- type HttpURL
- type IMiddleware
- type RegexpType
- type RouteRegexpOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var SessionEnable = false
SessionEnable 开启Session
View Source
var SessionTimeout = 1200
SessionTimeout 自动过期时间,单位:秒
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
Response *HttpResponse
Header collections.ReadonlyDictionary[string, string]
Cookie *HttpCookies
Session *HttpSession
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) IsActionResult ¶
func (httpContext *HttpContext) IsActionResult() bool
IsActionResult 是否为ActionResult类型
func (*HttpContext) ParseParams ¶ added in v0.8.0
func (httpContext *HttpContext) ParseParams() []reflect.Value
ParseParams 根据method映射入参
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 HttpRequest ¶
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) 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中间件
RouteRegexp *routeRegexp // 正则路由
Handler http.Handler // api处理函数
}
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 HttpSession ¶ added in v0.8.0
type HttpSession struct {
// contains filtered or unexported fields
}
func InitSession ¶ added in v0.8.0
func InitSession(w http.ResponseWriter, r *http.Request) *HttpSession
InitSession 初始化httpSession
func (*HttpSession) GetValue ¶ added in v0.8.0
func (r *HttpSession) GetValue(name string) any
GetValue 获取Session
func (*HttpSession) Remove ¶ added in v0.8.0
func (r *HttpSession) Remove(name string)
Remove 删除Session
func (*HttpSession) SetValue ¶ added in v0.8.0
func (r *HttpSession) SetValue(name string, val any)
SetValue 设置Session
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 )
type RouteRegexpOptions ¶ added in v0.8.0
Click to show internal directories.
Click to hide internal directories.