forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
134 lines (125 loc) · 4.18 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package context
import (
"bufio"
"html/template"
"io"
"time"
"github.com/kataras/iris/sessions/store"
"github.com/valyala/fasthttp"
)
type (
// IContext the interface for the Context
IContext interface {
IContextRenderer
IContextStorage
IContextBinder
IContextRequest
IContextResponse
SendMail(string, string, ...string) error
Log(string, ...interface{})
Reset(*fasthttp.RequestCtx)
GetRequestCtx() *fasthttp.RequestCtx
Clone() IContext
Do()
Next()
StopExecution()
IsStopped() bool
GetHandlerName() string
}
// IContextBinder is part of the IContext
IContextBinder interface {
ReadJSON(interface{}) error
ReadXML(interface{}) error
ReadForm(formObject interface{}) error
}
// IContextRenderer is part of the IContext
IContextRenderer interface {
Write(string, ...interface{})
HTML(int, string)
// Data writes out the raw bytes as binary data.
Data(status int, v []byte) error
// RenderWithStatus builds up the response from the specified template and bindings.
RenderWithStatus(status int, name string, binding interface{}, layout ...string) error
// Render same as .RenderWithStatus but with status to iris.StatusOK (200)
Render(name string, binding interface{}, layout ...string) error
// MustRender same as .Render but returns 500 internal server http status (error) if rendering fail
MustRender(name string, binding interface{}, layout ...string)
// TemplateString accepts a template filename, its context data and returns the result of the parsed template (string)
// if any error returns empty string
TemplateString(name string, binding interface{}, layout ...string) string
// MarkdownString parses the (dynamic) markdown string and returns the converted html string
MarkdownString(markdown string) string
// Markdown parses and renders to the client a particular (dynamic) markdown string
// accepts two parameters
// first is the http status code
// second is the markdown string
Markdown(status int, markdown string)
// JSON marshals the given interface object and writes the JSON response.
JSON(status int, v interface{}) error
// JSONP marshals the given interface object and writes the JSON response.
JSONP(status int, callback string, v interface{}) error
// Text writes out a string as plain text.
Text(status int, v string) error
// XML marshals the given interface object and writes the XML response.
XML(status int, v interface{}) error
ExecuteTemplate(*template.Template, interface{}) error
ServeContent(io.ReadSeeker, string, time.Time, bool) error
ServeFile(string, bool) error
SendFile(filename string, destinationName string) error
Stream(func(*bufio.Writer))
StreamWriter(cb func(writer *bufio.Writer))
StreamReader(io.Reader, int)
}
// IContextRequest is part of the IContext
IContextRequest interface {
Param(string) string
ParamInt(string) (int, error)
URLParam(string) string
URLParamInt(string) (int, error)
URLParams() map[string]string
MethodString() string
HostString() string
Subdomain() string
PathString() string
RequestPath(bool) string
RequestIP() string
RemoteAddr() string
RequestHeader(k string) string
PostFormValue(string) string
// PostFormMulti returns a slice of string from post request's data
PostFormMulti(string) []string
}
// IContextResponse is part of the IContext
IContextResponse interface {
// SetStatusCode sets the http status code
SetStatusCode(int)
// SetContentType sets the "Content-Type" header, receives the value
SetContentType(string)
// SetHeader sets the response headers first parameter is the key, second is the value
SetHeader(string, string)
Redirect(string, ...int)
RedirectTo(routeName string, args ...interface{})
// Errors
NotFound()
Panic()
EmitError(int)
//
}
// IContextStorage is part of the IContext
IContextStorage interface {
Get(string) interface{}
GetString(string) string
GetInt(string) int
Set(string, interface{})
SetCookie(*fasthttp.Cookie)
SetCookieKV(string, string)
RemoveCookie(string)
// Flash messages
GetFlash(string) string
GetFlashBytes(string) ([]byte, error)
SetFlash(string, string)
SetFlashBytes(string, []byte)
Session() store.IStore
SessionDestroy()
}
)