Documentation
¶
Index ¶
- Constants
- Variables
- func Bind(request *http.Request, result interface{}) (err error)
- func BindForm(values map[string][]string, result interface{}) (err error)
- func BindWith(source map[string]interface{}, result interface{}) (err error)
- func BindWithAdvanced(source map[string]interface{}, result interface{}, tag, cleanedTag string) error
- func BindWithTag(source map[string]interface{}, result interface{}, tag string) error
- func Decode(input string, alphabet *Alphabet) ([]byte, error)
- func DelEx(key string) error
- func Encode(input []byte, alphabet *Alphabet) string
- func GetEx(key string) ([]byte, error)
- func SetEx(key string, value []byte, time int32) error
- type Alphabet
- type Context
- func (c *Context) Bind(i interface{}) error
- func (c *Context) CorsHandler()
- func (c *Context) Err(code int32, s string)
- func (c *Context) FormValue(key, val string) string
- func (c *Context) Get(key string) map[string]interface{}
- func (c *Context) GetCookie(key string) (string, error)
- func (c *Context) GetName() string
- func (c *Context) GetRid() int32
- func (c *Context) GetString(key string) string
- func (c *Context) GetUid() int32
- func (c *Context) HTML(status int, s string)
- func (c *Context) JSON(status int, m map[string]interface{})
- func (c *Context) Map(m map[string]interface{})
- func (c *Context) Msg(code int32, s string)
- func (c *Context) NoAuth()
- func (c *Context) NoPermis()
- func (c *Context) NotFound()
- func (c *Context) OK()
- func (c *Context) Redirect(url string)
- func (c *Context) ReqValue(params ...string) map[string]interface{}
- func (c *Context) Resp() *RespBuilder
- func (c *Context) RespData() *RespBuilder
- func (c *Context) Result(m interface{})
- func (c *Context) Session() *Store
- func (c *Context) SessionID() (string, bool)
- func (c *Context) Set(key string, v map[string]interface{})
- func (c *Context) SetCookie(key, value string, minute int, args ...bool)
- func (c *Context) SetCookieAndDomain(key, value string, args ...bool)
- func (c *Context) SetString(key, value string)
- func (c *Context) UidAuth(id int32)
- func (c *Context) Write(status int, b []byte)
- func (c *Context) WriteString(s string)
- type CookieSession
- func (ses *CookieSession) Del(w http.ResponseWriter, r *http.Request)
- func (ses *CookieSession) GC()
- func (ses *CookieSession) Get(r *http.Request, key string) (interface{}, bool)
- func (ses *CookieSession) GetLastAccessTime(sessionID string) time.Time
- func (ses *CookieSession) GetSessionIDList() []string
- func (ses *CookieSession) GetVal(sessionID string, key string) interface{}
- func (ses *CookieSession) New(w http.ResponseWriter) string
- func (ses *CookieSession) Remove(sessionID string)
- func (ses *CookieSession) SessionID(r *http.Request) (string, bool)
- func (ses *CookieSession) Set(r *http.Request, key string, value interface{}) bool
- func (ses *CookieSession) SetVal(sessionID string, key string, value interface{}) error
- type HandlerFun
- type HandlerFunc
- type IRouter
- type JWTManager
- func (m *JWTManager) CleanupBlacklist()
- func (m *JWTManager) GenerateToken(config TokenConfig, customClaims map[string]interface{}) (string, error)
- func (m *JWTManager) RevokeToken(tokenString string, duration time.Duration)
- func (m *JWTManager) VerifyToken(tokenString string) (map[string]interface{}, error)
- type M
- type Payload
- type Provider
- type RedisPool
- type RedisSession
- func (ses *RedisSession) Del(w http.ResponseWriter, r *http.Request)
- func (ses *RedisSession) Get(r *http.Request, key string) (interface{}, bool)
- func (ses *RedisSession) GetSessionIDList() []string
- func (ses *RedisSession) GetVal(sessionID string, key string) interface{}
- func (ses *RedisSession) New(w http.ResponseWriter) string
- func (ses *RedisSession) Remove(sessionID string)
- func (ses *RedisSession) SessionID(r *http.Request) (string, bool)
- func (ses *RedisSession) Set(r *http.Request, key string, value interface{}) bool
- func (ses *RedisSession) SetVal(sessionID string, key string, value interface{}) error
- type Resource
- type RespBuilder
- func (b *RespBuilder) Code(code int) *RespBuilder
- func (b *RespBuilder) CurrentPage(page string) *RespBuilder
- func (b *RespBuilder) Data(data interface{}) *RespBuilder
- func (b *RespBuilder) Error(code int) *RespBuilder
- func (b *RespBuilder) Fail() *RespBuilder
- func (b *RespBuilder) JSON()
- func (b *RespBuilder) Message(msg string) *RespBuilder
- func (b *RespBuilder) NotFound() *RespBuilder
- func (b *RespBuilder) NotPermis() *RespBuilder
- func (b *RespBuilder) OK() *RespBuilder
- func (b *RespBuilder) PageSize(size string) *RespBuilder
- func (b *RespBuilder) Success() *RespBuilder
- func (b *RespBuilder) Total(total int32) *RespBuilder
- func (b *RespBuilder) TotalPage(totalPage int32) *RespBuilder
- type Result
- type ResultBuilder
- type RouteLogger
- type Router
- func (p *Router) Any(relativePath string, handler HandlerFunc, filter ...HandlerFun)
- func (p *Router) Cookie(cookieName string, maxLifeTime, cookieTime int64, secure bool)
- func (p *Router) Delete(relativePath string, handler HandlerFunc, filter ...HandlerFun)
- func (p *Router) Favicon(dirPath string)
- func (p *Router) File(relativePath string, filePath string, filter ...HandlerFun)
- func (p *Router) Get(relativePath string, handler HandlerFunc, filter ...HandlerFun)
- func (p *Router) GetSession(r *http.Request, key string) interface{}
- func (p *Router) Group(url string, h func(r *Router), params ...HandlerFun)
- func (p *Router) Handler(relativePath string, h http.HandlerFunc, f ...HandlerFun)
- func (p *Router) Logger(log RouteLogger)
- func (p *Router) NoFound(handler http.HandlerFunc)
- func (p *Router) Post(relativePath string, handler HandlerFunc, filter ...HandlerFun)
- func (p *Router) Put(relativePath string, handler HandlerFunc, filter ...HandlerFun)
- func (p *Router) Redis(cookieName string, maxLifeTime, cookieTime int64, secure bool, ...)
- func (p *Router) Route(url string, i IRouter, params ...HandlerFun)
- func (p *Router) Run(addr string)
- func (p *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (p *Router) ServerTimeout(readTimeout, writeTimeout int)
- func (p *Router) SessionExpires(minute int)
- func (p *Router) Static(relativePath string, dirPath string)
- func (p *Router) StaticDir(relativePath string, dir string)
- func (p *Router) StaticFs(relativePath string, handler http.HandlerFunc)
- func (p *Router) Use(h HandlerFun)
- func (p *Router) UseCors()
- func (p *Router) UseErrResp()
- type Session
- type Store
- type TokenConfig
Constants ¶
const BadGateway int = 502 //外部异常,通常为请求第三方
const BadReq int = 400 //提交错误
const Exception int = 500 //服务器异常,程序抛出异常
const (
ExpiresTime = 24
)
const Failed int = 410 //请求业务无法成功受理,业务自定义
const Forbidden int = 405 //访问被禁止
const NotAuthor int = 401 //认证失败或操作超时
const NotLimit int = 501 //不接受请求,如IP被限制
const NotPermis int = 403 //没有操作权限
const Repeat int = 402 //请求处理已完成或重复请求
const StatusError int = 406 //请求业务状态错误
const StatusNotFound int = 404 // fail,reason is not found
const StatusOk int = 200 // success
const StatusUnknown int = 500 // fail,reason is unknown
Variables ¶
var ( BitcoinAlphabet = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") IPFSAlphabet = NewAlphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") FlickrAlphabet = NewAlphabet("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ") RippleAlphabet = NewAlphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz") )
Alphabet: copy from https://en.wikipedia.org/wiki/Base58
var ( ErrTokenExpired = errors.New("token has expired") ErrInvalidToken = errors.New("invalid token") ErrTokenMalformed = errors.New("token is malformed") )
错误定义
var (
ErrorInvalidBase58String = errors.New("invalid base58 string")
)
Errors
var (
Type = map[string]int{
"Any": 0,
"GET": 1,
"POST": 2,
"DELETE": 3,
"PUT": 4,
}
)
Functions ¶
func BindWithAdvanced ¶
func BindWithTag ¶
Types ¶
type Alphabet ¶
type Alphabet struct {
// contains filtered or unexported fields
}
Alphabet The base58 alphabet object.
func NewAlphabet ¶
NewAlphabet create a custom alphabet from 58-length string. Note: len(rune(alphabet)) must be 58.
type Context ¶
type Context struct {
Writer http.ResponseWriter
Request *http.Request
Sessions Session
}
func (*Context) CorsHandler ¶ added in v1.12.15
func (c *Context) CorsHandler()
func (*Context) Resp ¶ added in v1.12.1
func (c *Context) Resp() *RespBuilder
func (*Context) RespData ¶ added in v1.12.1
func (c *Context) RespData() *RespBuilder
func (*Context) SetCookieAndDomain ¶ added in v1.12.15
使用根域名,通常用于跨域访问cookie,过期时间为cookieExpiresTime
func (*Context) WriteString ¶
type CookieSession ¶
type CookieSession struct {
// contains filtered or unexported fields
}
Session会话管理
func NewCookieSession ¶
func NewCookieSession(cookieName string, maxLifeTime, cookieTime int64, secure bool) *CookieSession
创建会话管理器(cookieName:在浏览器中cookie的名字;maxLifeTime:最长生命周期)
func (*CookieSession) Del ¶
func (ses *CookieSession) Del(w http.ResponseWriter, r *http.Request)
结束Session
func (*CookieSession) Get ¶
func (ses *CookieSession) Get(r *http.Request, key string) (interface{}, bool)
func (*CookieSession) GetLastAccessTime ¶
func (ses *CookieSession) GetLastAccessTime(sessionID string) time.Time
更新最后访问时间
func (*CookieSession) GetSessionIDList ¶
func (ses *CookieSession) GetSessionIDList() []string
得到sessionID列表
func (*CookieSession) GetVal ¶
func (ses *CookieSession) GetVal(sessionID string, key string) interface{}
得到session里面的值
func (*CookieSession) New ¶
func (ses *CookieSession) New(w http.ResponseWriter) string
在开始页面登陆页面,开始Session
func (*CookieSession) SessionID ¶
func (ses *CookieSession) SessionID(r *http.Request) (string, bool)
type HandlerFun ¶
type HandlerFun func(HandlerFunc) HandlerFunc
type HandlerFunc ¶
func Cors ¶ added in v1.12.15
func Cors(next HandlerFunc) HandlerFunc
func ErrRespone ¶ added in v1.8.26
func ErrRespone(next HandlerFunc) HandlerFunc
type JWTManager ¶ added in v1.12.13
type JWTManager struct {
// contains filtered or unexported fields
}
JWT管理器
func (*JWTManager) CleanupBlacklist ¶ added in v1.12.13
func (m *JWTManager) CleanupBlacklist()
清理过期的黑名单令牌
func (*JWTManager) GenerateToken ¶ added in v1.12.13
func (m *JWTManager) GenerateToken(config TokenConfig, customClaims map[string]interface{}) (string, error)
生成令牌
func (*JWTManager) RevokeToken ¶ added in v1.12.13
func (m *JWTManager) RevokeToken(tokenString string, duration time.Duration)
吊销令牌
func (*JWTManager) VerifyToken ¶ added in v1.12.13
func (m *JWTManager) VerifyToken(tokenString string) (map[string]interface{}, error)
验证令牌
type Payload ¶ added in v1.12.13
type Payload struct {
Issuer string `json:"iss,omitempty"`
Subject string `json:"sub,omitempty"`
Audience string `json:"aud,omitempty"`
IssuedAt int64 `json:"iat,omitempty"`
ExpiresAt int64 `json:"exp,omitempty"`
NotBefore int64 `json:"nbf,omitempty"`
}
Payload 使用更多标准字段 omitempty 是 Go 语言中 JSON 编码的一个特殊标签,它的作用是在序列化 JSON 时, 如果对应的字段为零值(nil、空字符串、0、false 等),则不会被包含在生成的 JSON 中。
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
—————————————————————————— 会话
type RedisSession ¶
type RedisSession struct {
// contains filtered or unexported fields
}
Session会话管理
func NewRedisSession ¶
func NewRedisSession(cookieName string, maxLifeTime, cookieTime int64, secure bool, RedisHost, RedisPwd string, database ...int) *RedisSession
创建会话管理器(cookieName:在浏览器中cookie的名字;maxLifeTime:最长生命周期)
func (*RedisSession) Del ¶
func (ses *RedisSession) Del(w http.ResponseWriter, r *http.Request)
结束Session
func (*RedisSession) Get ¶
func (ses *RedisSession) Get(r *http.Request, key string) (interface{}, bool)
func (*RedisSession) GetSessionIDList ¶
func (ses *RedisSession) GetSessionIDList() []string
得到sessionID列表
func (*RedisSession) GetVal ¶
func (ses *RedisSession) GetVal(sessionID string, key string) interface{}
得到session里面的值
func (*RedisSession) New ¶
func (ses *RedisSession) New(w http.ResponseWriter) string
在开始页面登陆页面,开始Session
type RespBuilder ¶ added in v1.25.9
type RespBuilder struct {
// contains filtered or unexported fields
}
---- Builder ----
func NewResp ¶ added in v1.12.1
func NewResp(w http.ResponseWriter) *RespBuilder
func (*RespBuilder) Code ¶ added in v1.25.9
func (b *RespBuilder) Code(code int) *RespBuilder
---- 通用方法 ----
func (*RespBuilder) CurrentPage ¶ added in v1.25.9
func (b *RespBuilder) CurrentPage(page string) *RespBuilder
func (*RespBuilder) Data ¶ added in v1.25.9
func (b *RespBuilder) Data(data interface{}) *RespBuilder
func (*RespBuilder) Error ¶ added in v1.25.9
func (b *RespBuilder) Error(code int) *RespBuilder
func (*RespBuilder) Message ¶ added in v1.25.9
func (b *RespBuilder) Message(msg string) *RespBuilder
func (*RespBuilder) NotPermis ¶ added in v1.25.9
func (b *RespBuilder) NotPermis() *RespBuilder
没有操作权限
func (*RespBuilder) PageSize ¶ added in v1.25.9
func (b *RespBuilder) PageSize(size string) *RespBuilder
func (*RespBuilder) Total ¶ added in v1.25.9
func (b *RespBuilder) Total(total int32) *RespBuilder
func (*RespBuilder) TotalPage ¶ added in v1.25.9
func (b *RespBuilder) TotalPage(totalPage int32) *RespBuilder
type ResultBuilder ¶ added in v1.8.26
type ResultBuilder struct {
// contains filtered or unexported fields
}
type RouteLogger ¶
type RouteLogger interface {
Println(v ...interface{})
}
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) Any ¶
func (p *Router) Any(relativePath string, handler HandlerFunc, filter ...HandlerFun)
func (*Router) Delete ¶
func (p *Router) Delete(relativePath string, handler HandlerFunc, filter ...HandlerFun)
func (*Router) File ¶
func (p *Router) File(relativePath string, filePath string, filter ...HandlerFun)
func (*Router) Get ¶
func (p *Router) Get(relativePath string, handler HandlerFunc, filter ...HandlerFun)
func (*Router) Handler ¶
func (p *Router) Handler(relativePath string, h http.HandlerFunc, f ...HandlerFun)
route.handler("/user", handlerFunc) 访问: /user/abc 匹配
func (*Router) Logger ¶
func (p *Router) Logger(log RouteLogger)
func (*Router) NoFound ¶
func (p *Router) NoFound(handler http.HandlerFunc)
func (*Router) Post ¶
func (p *Router) Post(relativePath string, handler HandlerFunc, filter ...HandlerFun)
func (*Router) Put ¶
func (p *Router) Put(relativePath string, handler HandlerFunc, filter ...HandlerFun)
func (*Router) ServerTimeout ¶ added in v1.8.26
func (*Router) SessionExpires ¶ added in v1.12.19
func (*Router) StaticFs ¶
func (p *Router) StaticFs(relativePath string, handler http.HandlerFunc)
自行处理文件实现,如OSS/FileDB/S3/虚拟文件系统
func (*Router) UseErrResp ¶ added in v1.8.26
func (p *Router) UseErrResp()
type Session ¶
type Session interface {
New(w http.ResponseWriter) string
Del(w http.ResponseWriter, r *http.Request)
Remove(sessionID string)
SetVal(sessionID string, key string, value interface{}) error
GetVal(sessionID string, key string) interface{}
SessionID(r *http.Request) (string, bool)
Set(r *http.Request, key string, value interface{}) bool
Get(r *http.Request, key string) (interface{}, bool)
}