-
Notifications
You must be signed in to change notification settings - Fork 10
/
ctx.go
87 lines (64 loc) · 1.62 KB
/
ctx.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package twig
import (
"io"
"mime/multipart"
"net/http"
"net/url"
)
// Ctx 接口,用于向Handler传递Twig上下文数据,并提供简化操作完成请求处理
type Ctx interface {
Req() *http.Request
Resp() *ResponseWrap
// IsTls 当前请求是否为Tls
IsTls() bool
//IsWebSocket 当前请求是否是WebSocket
IsWebSocket() bool
// IsXMLHttpRequest 当前请求是否为Ajax
IsXMLHttpRequest() bool
// Scheme 当前请求的的Scheme
Scheme() string
// RealIP 对方的IP
RealIP() string
// Path 当前请求的注册路径
Path() string
// Param 获取当前请求的URL参数
Param(string) string
QueryParam(string) string
QueryParams() url.Values
QueryString() string
FormValue(string) string
FormParams() (url.Values, error)
FormFile(name string) (*multipart.FileHeader, error)
MultipartForm() (*multipart.Form, error)
File(file string) error
Attachment(file, name string) error
Inline(file, name string) error
Get(string) interface{}
Set(string, interface{})
// JSON JSON方式输出
JSON(int, interface{}) error
JSONP(int, string, interface{}) error
XML(int, interface{}) error
Blob(int, string, []byte) error
Stream(int, string, io.Reader) error
String(int, string) error
Stringf(int, string, ...interface{}) error
Cookie(string) (*http.Cookie, error)
SetCookie(*http.Cookie)
Cookies() []*http.Cookie
NoContent() error
Error(error)
Redirect(int, string) error
Twig() *Twig
Logger() Logger
PreCtx
}
type MuxerCtx interface {
Handler() HandlerFunc
Release()
Reset(http.ResponseWriter, *http.Request, *Twig)
Ctx
}
// PreCtx Pre中间件中使用
type PreCtx interface {
}