-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
59 lines (49 loc) · 1.48 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Package contextx
//
// @author: xwc1125
package contextx
import (
"context"
"mime/multipart"
"net/http"
)
const (
ContentTypeHeaderKey = "Content-Type"
ContentDispositionHeaderKey = "Content-Disposition"
ContentLengthHeaderKey = "Content-Length"
ContentEncodingHeaderKey = "Content-Encoding"
)
type Handler func(Context)
type Context interface {
context.Context
Request() *http.Request
ResponseWriter() http.ResponseWriter
RequestId() string
Next()
Abort() // 终止。如果授权失败(例如:密码不匹配),请调用Abort以确保不调用此请求的其余处理程序
AbortWithStatus(code int)
AbortWithStatusJSON(code int, jsonObj interface{})
IsAborted() bool // 判断当前context是否已终止
Param(key string) string
Query(key string) string
PostForm(key string) string
FormFile(name string) (*multipart.FileHeader, error)
MultipartForm() (*multipart.Form, error)
SaveUploadedFile(file *multipart.FileHeader, dst string) error
Bind(obj interface{}, bindType ...string) error
ContentType() string
// =========METADATA=======
Set(key string, value interface{})
Get(key string) (value interface{}, exists bool)
GetString(key string) (s string)
GetBool(key string) (b bool)
GetInt64(key string) (i64 int64)
// =========RESPONSE=======
Status(code int)
GetStatus() int
Header(key, value string)
GetHeader(key string) string
SetCookie(cookie *http.Cookie)
GetCookie(name string) (string, error)
Redirect(code int, location string)
}