Documentation
¶
Index ¶
- Variables
- func AddSalt(rnd []byte, salt string) string
- func CopyStruct(dsc, src interface{}, handle func(name string, dsc, src reflect.Value) bool) error
- func CopyStructDeep(dsc, src interface{}, handle func(name string, dsc, src reflect.Value) bool) error
- func DepthField(s interface{}, index ...interface{}) (field interface{}, err error)
- func ExecFunc(f interface{}, args ...interface{}) ([]interface{}, error)
- func ForMethod(x interface{}) string
- func ForType(x interface{}, lower bool, depth int) string
- func GenerateRandom(length int) ([]byte, error)
- func GenerateRandomId(rnd []byte) error
- func GenerateRandomString(length int) (string, error)
- func InDirect(v reflect.Value) reflect.Value
- func PagePath(root, p string, index []string) (os.FileInfo, string, error)
- type Cookie
- type Cookier
- type DotContexter
- type DynamicTemplateFunc
- type DynamicTemplater
- type ExecCall
- type ExitCall
- type Forward
- type Globaler
- type PluginHTTP
- type PluginHTTPClient
- type PluginRPC
- type PluginRPCClient
- type PluginType
- type Pluginer
- type Responser
- type Route
- type ServerHandlerDynamic
- func (T *ServerHandlerDynamic) Execute(bufw io.Writer, dock interface{}) (err error)
- func (T *ServerHandlerDynamic) Parse(r io.Reader) (err error)
- func (T *ServerHandlerDynamic) ParseFile(path string) error
- func (T *ServerHandlerDynamic) ParseText(name, content string) error
- func (T *ServerHandlerDynamic) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- type ServerHandlerStatic
- type Session
- type Sessioner
- type Sessions
- func (T *Sessions) DelSession(id string)
- func (T *Sessions) GetSession(id string) (Sessioner, bool)
- func (T *Sessions) Len() int
- func (T *Sessions) NewSession(id string) Sessioner
- func (T *Sessions) ProcessDeadAll() []interface{}
- func (T *Sessions) Session(rw http.ResponseWriter, req *http.Request) Sessioner
- func (T *Sessions) SessionId(req *http.Request) (id string, err error)
- func (T *Sessions) SetSession(id string, s Sessioner) Sessioner
- type Site
- type SiteMan
- type SitePool
- type TemplateDot
- func (T *TemplateDot) Context() context.Context
- func (T *TemplateDot) Cookie() Cookier
- func (T *TemplateDot) Defer(call interface{}, args ...interface{}) error
- func (T *TemplateDot) Free()
- func (T *TemplateDot) Global() Globaler
- func (T *TemplateDot) Header() http.Header
- func (T *TemplateDot) Request() *http.Request
- func (T *TemplateDot) RequestLimitSize(l int64) *http.Request
- func (T *TemplateDot) Response() Responser
- func (T *TemplateDot) ResponseWriter() http.ResponseWriter
- func (T *TemplateDot) RootDir(upath string) string
- func (T *TemplateDot) Session() Sessioner
- func (T *TemplateDot) Swap() *vmap.Map
- func (T *TemplateDot) WithContext(ctx context.Context)
- type TemplateDoter
Constants ¶
This section is empty.
Variables ¶
var ( SiteContextKey = &contextKey{"web-site"} ListenerContextKey = &contextKey{"web-listener"} ConnContextKey = &contextKey{"web-conn"} PluginContextKey = &contextKey{"web-plugin"} )
上下文中使用的key
var DefaultSitePool = NewSitePool() // 网站池(默认)
Functions ¶
func CopyStruct ¶
CopyStruct 结构字段从src 复制 dsc,不需要相同的结构。他只复制相同类型的字段。
dsc, src interface{} 目标,源结构
handle func(name string, dsc, src reflect.Value) bool 排除处理函数,返回true跳过
error 错误
func CopyStructDeep ¶
func DepthField ¶
func DepthField(s interface{}, index ...interface{}) (field interface{}, err error)
DepthField 快速深入读取字段
s interface{} Struct
ndex ... interface{} 字段
field interface{} 字段
err error 错误
例:
type A struct {
B
}
type B struct {
C
F map[string]string
G []string
}
type C struct {
D int
}
func main(){
a := A{}
fidld, err := DepthField(a, "B", "C", "D")
fmt.Println(fidld, err)
//0 <nil>
}
func ExecFunc ¶ added in v2.4.0
func ExecFunc(f interface{}, args ...interface{}) ([]interface{}, error)
ExecFunc 执行函数调用
call interface{} 函数
args ... interface{} 参数或更多个函数是函数的参数
[]interface{} 返回直
error 错误
func ForMethod ¶
func ForMethod(x interface{}) string
ForMethod 遍历方法
x interface{} 类型
all bool true不可导出一样可以打印出来
string 字符串
Types ¶
type Cookie ¶
type Cookie struct {
R *http.Request //请求
W http.ResponseWriter //响应
}
func (*Cookie) Add ¶
func (c *Cookie) Add(name, value, path, domain string, maxAge int, secure, only bool, sameSite http.SameSite)
Add 增加,写入一条Cookie,可以写入多条Cookie保存至浏览器
name string 名称 value string 值 path string 路径 domain string 域 maxAge int 过期时间,以毫秒为单位 secure bool 源,如果通过 SSL 连接 (HTTPS) 传输 Cookie,则为 true;否则为 false。默认值为 false。 only bool 验证,如果 Cookie 具有 HttpOnly 属性且不能通过客户端脚本(JS)访问,则为 true;否则为 false。默认为 false。 sameSite http.SameSite 是否严格模式
type DotContexter ¶
type DynamicTemplateFunc ¶ added in v2.0.9
type DynamicTemplateFunc func(*ServerHandlerDynamic) DynamicTemplater
type DynamicTemplater ¶ added in v2.0.9
type ExecCall ¶ added in v2.4.6
type ExecCall struct {
// contains filtered or unexported fields
}
ExecCall 执行函数
type ExitCall ¶ added in v2.4.2
type ExitCall struct {
// contains filtered or unexported fields
}
ExitCall 过期函数
type Forward ¶
type Globaler ¶
type Globaler interface {
Set(key, val interface{}) // 设置
Has(key interface{}) bool // 检查
Get(key interface{}) interface{} // 读取
Del(key interface{}) // 删除
SetExpired(key interface{}, d time.Duration) // 设置KEY有效期,过期会自动删除
SetExpiredCall(key interface{}, d time.Duration, f func(interface{})) // 设置KEY有效期,过期会自动删除,并调用函数
Reset() // 重置
}
type PluginHTTP ¶
type PluginHTTP interface {
Type() PluginType // 类型
ServeHTTP(w http.ResponseWriter, r *http.Request) // 服务HTTP
RoundTrip(r *http.Request) (resp *http.Response, err error) // 代理
CancelRequest(req *http.Request) // 取消HTTP请求
CloseIdleConnections() // 关闭空闲连接
RegisterProtocol(scheme string, rt http.RoundTripper) // 注册新协议
}
http插件接口
type PluginHTTPClient ¶
type PluginHTTPClient struct {
Tr *http.Transport // 客户端
Addr string // 地址
Scheme string // 协议(用于默认填充)
Host string // 请求Host(用于默认填充)
Dialer *net.Dialer
}
插件HTTP客户端
func (*PluginHTTPClient) Connection ¶
func (T *PluginHTTPClient) Connection() (PluginHTTP, error)
快速连接HTTP
PluginHTTP 插件HTTP error 错误
type PluginRPC ¶
type PluginRPC interface {
Type() PluginType // 类型
Register(value interface{}) // 注册struct类型
Call(name string, arg interface{}) (interface{}, error) // 调用
Discard() error // 废弃连接
Close() error // 关闭
}
rpc插件接口
type PluginRPCClient ¶
type PluginRPCClient struct {
ConnPool *vconnpool.ConnPool // 连接池
Addr string // 地址
Path string // 路径
}
插件RPC客户端
func (*PluginRPCClient) Connection ¶
func (T *PluginRPCClient) Connection() (PluginRPC, error)
快速连接RPC
PluginRPC 插件RPC error 错误
type Responser ¶
type Responser interface {
Write([]byte) (int, error) // 写入字节
WriteString(string) (int, error) // 写入字符串
ReadFrom(io.Reader) (int64, error) // 读取并写入
Redirect(string, int) // 转向
WriteHeader(int) // 状态码
Error(string, int) // 错误
Flush() // 刷新缓冲
Push(target string, opts *http.PushOptions) error // HTTP/2推送
Hijack() (net.Conn, *bufio.ReadWriter, error) // 劫持,能双向互相发送信息
}
type Route ¶
type Route struct {
HandlerError http.HandlerFunc // 错误访问处理
// contains filtered or unexported fields
}
func (*Route) HandleFunc ¶
HandleFunc 绑定处理函数,匹配的网址支持正则,这说明你要严格的检查。
url string 网址,支持正则匹配 handler func(w ResponseWriter, r *Request) 处理函数
func (*Route) ServeHTTP ¶
func (T *Route) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP 服务HTTP
w ResponseWriter 响应 r *Request 请求
func (*Route) SetSiteMan ¶ added in v2.4.8
SetSiteMan 设置站点管理,将会携带在请求上下文中 siteMan *SiteMan 站点
type ServerHandlerDynamic ¶
type ServerHandlerDynamic struct {
// 必须的
RootPath string // 根目录
PagePath string // 主模板文件路径
// 可选的
BuffSize int // 缓冲块大小
Site *Site // 网站配置
Context context.Context // 上下文
Module map[string]DynamicTemplateFunc // 支持更动态文件类型
StaticAt func(u *url.URL, r io.Reader, l int) (int, error) // 静态结果。仅在 .ServeHTTP 方法中使用
ReadFile func(u *url.URL, filePath string) (io.Reader, time.Time, error) // 读取文件。仅在 .ServeHTTP 方法中使用
ReplaceParse func(name string, p []byte) []byte
// contains filtered or unexported fields
}
ServerHandlerDynamic 处理动态页面文件
func (*ServerHandlerDynamic) Execute ¶
func (T *ServerHandlerDynamic) Execute(bufw io.Writer, dock interface{}) (err error)
Execute 执行模板
bufw *bytes.Buffer 模板返回数据
dock interface{} 与模板对接接口
error 错误
func (*ServerHandlerDynamic) Parse ¶
func (T *ServerHandlerDynamic) Parse(r io.Reader) (err error)
Parse 解析模板
r io.Reader 模板内容 error 错误
func (*ServerHandlerDynamic) ParseFile ¶
func (T *ServerHandlerDynamic) ParseFile(path string) error
ParseFile 解析模板
path string 模板文件路径,如果为空,默认使用RootPath,PagePath字段 error 错误
func (*ServerHandlerDynamic) ParseText ¶
func (T *ServerHandlerDynamic) ParseText(name, content string) error
ParseText 解析模板
name, content string 模板名称, 模板内容 error 错误
func (*ServerHandlerDynamic) ServeHTTP ¶
func (T *ServerHandlerDynamic) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP 服务HTTP
rw http.ResponseWriter 响应 req *http.Request 请求
type ServerHandlerStatic ¶
type ServerHandlerStatic struct {
RootPath, PagePath string // 根目录, 页路径
PageExpired int64 // 页面过期时间(秒为单位)
BuffSize int // 缓冲块大小
// contains filtered or unexported fields
}
ServerHandlerStatic 处理静态页面文件
func (*ServerHandlerStatic) ServeHTTP ¶
func (T *ServerHandlerStatic) ServeHTTP(rw http.ResponseWriter, req *http.Request)
serveHTTP 服务HTTP
rw http.ResponseWriter 响应 req *http.Request 请求
type Session ¶
type Session struct {
vmap.Map // 数据,用户存储的数据
ExitCall ExitCall // 退回调用函数
// contains filtered or unexported fields
}
Session 会话用于用户保存数据
type Sessioner ¶
type Sessioner interface {
Token() string // 编号
Set(key, val interface{}) // 设置
Has(key interface{}) bool // 判断
Get(key interface{}) interface{} // 读取
GetHas(key interface{}) (val interface{}, ok bool) // 读取判断
Del(key interface{}) // 删除
SetExpired(key interface{}, d time.Duration) // 过期
SetExpiredCall(key interface{}, d time.Duration, f func(interface{})) // 过期调用
Reset() // 重置
Defer(call interface{}, args ...interface{}) error // 退出调用
Free() // 释放调用
}
Sessioner 用户独立的内存存储接口
type Sessions ¶
type Sessions struct {
Expired time.Duration // 保存session时间长
Name string // 标识名称。用于Cookie
Size int // 会话ID长度。用于Cookie
Salt string // 加盐,由于计算机随机数是伪随机数。(可默认为空)。用于Cookie
ActivationID bool // 为true,保持会话ID。意思就是会话ID过期了,可以激活再次使用。用于Cookie
// contains filtered or unexported fields
}
Sessions集
func (*Sessions) ProcessDeadAll ¶
func (T *Sessions) ProcessDeadAll() []interface{}
ProcessDeadAll 定时来处理过期的Session
[]string 过期的ID名称
type Site ¶
type Site struct {
Sessions *Sessions // 会话集
Global Globaler // Global
RootDir func(path string) string // 网站的根目录z
Extend interface{} // 接口类型,可以自己存在任何类型
// contains filtered or unexported fields
}
Site 站点数据存储
type SiteMan ¶
type SiteMan struct {
// contains filtered or unexported fields
}
type SitePool ¶
type SitePool struct {
// contains filtered or unexported fields
}
SitePool 网站池
func NewSitePool ¶
func NewSitePool() *SitePool
func (*SitePool) NewSite ¶
NewSite 创建一个站点,如果存在返回已经存在的。Sessions 使用默认的设置,你需要修改它。
name string 站点name *Site 站点
func (*SitePool) SetRecoverSession ¶
SetRecoverSession 设置回收无效的会话间隔。默认为1秒
d time.Duration 回收时间隔,不可以等于或小于0,否则CPU爆增
type TemplateDot ¶
type TemplateDot struct {
R *http.Request // 请求
W http.ResponseWriter // 响应
BuffSize int // 缓冲块大小
Site *Site // 网站配置
Writed bool // 表示已经调用写入到客户端。这个是只读的
// contains filtered or unexported fields
}
模板点
func (*TemplateDot) Context ¶
func (T *TemplateDot) Context() context.Context
Context 上下文
context.Context 上下文
func (*TemplateDot) Defer ¶
func (T *TemplateDot) Defer(call interface{}, args ...interface{}) error
Defer 在用户会话时间过期后,将被调用。
call interface{} 函数
args ... interface{} 参数或更多个函数是函数的参数
error 错误
例:
.Defer(fmt.Println, "1", "2")
.Defer(fmt.Printf, "%s", "汉字")
func (*TemplateDot) Request ¶
func (T *TemplateDot) Request() *http.Request
Request 用户的请求信息
*http.Request 请求
func (*TemplateDot) RequestLimitSize ¶
func (T *TemplateDot) RequestLimitSize(l int64) *http.Request
RequestLimitSize 请求限制大小
l int64 复制body大小 *http.Request 请求
func (*TemplateDot) Response ¶
func (T *TemplateDot) Response() Responser
Response 数据写入响应
Responser 响应
func (*TemplateDot) ResponseWriter ¶
func (T *TemplateDot) ResponseWriter() http.ResponseWriter
ResponseWriter 数据写入响应,http 的响应接口,调用这个接口后,模板中的内容就不会显示页客户端去
http.ResponseWriter 响应
func (*TemplateDot) RootDir ¶
func (T *TemplateDot) RootDir(upath string) string
RootDir 网站的根目录
upath string 页面路径 string 根目录
func (*TemplateDot) Session ¶
func (T *TemplateDot) Session() Sessioner
Session 用户的会话缓存
Sessioner 会话缓存
func (*TemplateDot) WithContext ¶
func (T *TemplateDot) WithContext(ctx context.Context)
WithContext 替换上下文
ctx context.Context 上下文
type TemplateDoter ¶
type TemplateDoter interface {
RootDir(path string) string // 网站的根目录
Request() *http.Request // 用户的请求信息
RequestLimitSize(l int64) *http.Request // 请求限制大小
Header() http.Header // 标头
Response() Responser // 数据写入响应
ResponseWriter() http.ResponseWriter // 数据写入响应
Session() Sessioner // 用户的会话缓存
Global() Globaler // 全站缓存
Cookie() Cookier // 用户的Cookie
Swap() *vmap.Map // 信息交换
Defer(call interface{}, args ...interface{}) error // 退回调用
DotContexter // 上下文
}
TemplateDoter 可以在模本中使用的方法