Documentation ¶
Index ¶
- Variables
- func CreateToken(username string) (string, error)
- func JWTAuth() func(c *Context)
- type Claims
- type Context
- func (c *Context) Abort(code int)
- func (c *Context) BindJSON(js interface{}) error
- func (c *Context) Data(code int, data []byte)
- func (c *Context) Error(err error, meta interface{})
- func (c *Context) Fail(code int, err error)
- func (c *Context) Form(key string) string
- func (c *Context) Get(key string) (interface{}, error)
- func (c *Context) HTML(code int, name string, data interface{})
- func (c *Context) Header(key, value string)
- func (c *Context) JSON(code int, obj interface{})
- func (c *Context) MustGet(key string) interface{}
- func (c *Context) Name(key string) string
- func (c *Context) Next()
- func (c *Context) Query(key string) interface{}
- func (c *Context) QueryFloat64(key string) float64
- func (c *Context) QueryInt(key string) int
- func (c *Context) QueryInt32(key string) int32
- func (c *Context) QueryInt64(key string) int64
- func (c *Context) QueryString(key string) string
- func (c *Context) Set(key string, item interface{})
- func (c *Context) Status(code int)
- func (c *Context) String(code int, msg string)
- func (c *Context) XML(code int, obj interface{})
- type Engine
- type ErrorMsg
- type HandlerFunc
- type K
- type Path
- type Paths
- type RouterGroup
- func (rt *RouterGroup) DELETE(path string, handlers ...HandlerFunc)
- func (rt *RouterGroup) GET(path string, handlers ...HandlerFunc)
- func (rt *RouterGroup) Group(component string, handlers ...HandlerFunc) *RouterGroup
- func (rt *RouterGroup) Handle(method, p string, handlers []HandlerFunc)
- func (rt *RouterGroup) PATCH(path string, handlers ...HandlerFunc)
- func (rt *RouterGroup) POST(path string, handlers ...HandlerFunc)
- func (rt *RouterGroup) PUT(path string, handlers ...HandlerFunc)
- func (rt *RouterGroup) Use(middlewares ...HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( //TokenDuration token持续时间 TokenDuration = time.Hour * 2 //JWTSecret token密钥 JWTSecret = []byte("KeingWebSecret") )
Functions ¶
func CreateToken ¶ added in v0.1.2
CreateToken 生成token
Types ¶
type Claims ¶ added in v0.1.2
type Claims struct { Username string `json:"username"` jwt.StandardClaims }
Claims 用户信息类,作为生成token的参数
func ParseToken ¶ added in v0.1.2
ParseToken 将token字符串解析为用户信息类
type Context ¶
type Context struct { Request *http.Request Writer http.ResponseWriter Params httprouter.Params Errors []ErrorMsg Keys map[string]interface{} Code int // contains filtered or unexported fields }
Context 用来响应的上下文
func (*Context) Header ¶ added in v0.2.1
Header c.Writer.Header().Set(key, value)的快捷方式 如果value为空,则删除头
func (*Context) Name ¶
Name 路由值获取 例如: /hello/:name request: localhost:8080/hello/keing c.Name("name")将获取keing
func (*Context) QueryFloat64 ¶
QueryFloat64 键值获取(转化为float64)
func (*Context) QueryInt32 ¶
QueryInt32 键值获取(转化为int32)
func (*Context) QueryInt64 ¶
QueryInt64 键值获取(转化为int64)
func (*Context) QueryString ¶
QueryString 键值获取(转化为sring)
type Engine ¶
type Engine struct { *RouterGroup HTMLTemplates *template.Template // contains filtered or unexported fields }
Engine 路由核心
func (*Engine) ServeHTTP ¶ added in v0.1.1
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP 使用ServeHTTP使路由实现 http.Handler的接口
func (*Engine) SetHTMLTemplates ¶ added in v0.1.2
SetHTMLTemplates 确保HTML模板无错误,再将其赋予变量中
type ErrorMsg ¶
type ErrorMsg struct { Message string `json:"msg"` Meta interface{} `json:"meta"` }
ErrorMsg 错误信息结构
type Paths ¶
type Paths struct {
// contains filtered or unexported fields
}
Paths 全部路径结构
func (*Paths) ShowAllPathString ¶
func (p *Paths) ShowAllPathString()
ShowAllPathString 获取当前所里路径并格式化输出
type RouterGroup ¶ added in v0.1.1
type RouterGroup struct { Handlers []HandlerFunc // contains filtered or unexported fields }
RouterGroup 路由组结构
func (*RouterGroup) DELETE ¶ added in v0.1.1
func (rt *RouterGroup) DELETE(path string, handlers ...HandlerFunc)
DELETE DELETE请求
func (*RouterGroup) GET ¶ added in v0.1.1
func (rt *RouterGroup) GET(path string, handlers ...HandlerFunc)
GET GET请求
func (*RouterGroup) Group ¶ added in v0.1.1
func (rt *RouterGroup) Group(component string, handlers ...HandlerFunc) *RouterGroup
Group 创建一个路由组,并初始化
func (*RouterGroup) Handle ¶ added in v0.1.1
func (rt *RouterGroup) Handle(method, p string, handlers []HandlerFunc)
Handle 给路由添加路由函数
func (*RouterGroup) PATCH ¶ added in v0.1.1
func (rt *RouterGroup) PATCH(path string, handlers ...HandlerFunc)
PATCH PATCH请求
func (*RouterGroup) POST ¶ added in v0.1.1
func (rt *RouterGroup) POST(path string, handlers ...HandlerFunc)
POST POST请求
func (*RouterGroup) PUT ¶ added in v0.1.1
func (rt *RouterGroup) PUT(path string, handlers ...HandlerFunc)
PUT PUT请求
func (*RouterGroup) Use ¶ added in v0.1.1
func (rt *RouterGroup) Use(middlewares ...HandlerFunc)
Use 使用中间件
Source Files ¶
Click to show internal directories.
Click to hide internal directories.