f535916f by 傅小黑

add comments for context package.

1 parent 673993fa
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
6 "github.com/astaxie/beego/middleware" 6 "github.com/astaxie/beego/middleware"
7 ) 7 )
8 8
9 // Http request context struct including BeegoInput, BeegoOutput, http.Request and http.ResponseWriter.
10 // BeegoInput and BeegoOutput provides some api to operate request and response more easily.
9 type Context struct { 11 type Context struct {
10 Input *BeegoInput 12 Input *BeegoInput
11 Output *BeegoOutput 13 Output *BeegoOutput
...@@ -13,11 +15,16 @@ type Context struct { ...@@ -13,11 +15,16 @@ type Context struct {
13 ResponseWriter http.ResponseWriter 15 ResponseWriter http.ResponseWriter
14 } 16 }
15 17
18 // Redirect does redirection to localurl with http header status code.
19 // It sends http response header directly.
16 func (ctx *Context) Redirect(status int, localurl string) { 20 func (ctx *Context) Redirect(status int, localurl string) {
17 ctx.Output.Header("Location", localurl) 21 ctx.Output.Header("Location", localurl)
18 ctx.Output.SetStatus(status) 22 ctx.Output.SetStatus(status)
19 } 23 }
20 24
25 // Abort stops this request.
26 // if middleware.ErrorMaps exists, panic body.
27 // if middleware.HTTPExceptionMaps exists, panic HTTPException struct with status and body string.
21 func (ctx *Context) Abort(status int, body string) { 28 func (ctx *Context) Abort(status int, body string) {
22 ctx.Output.SetStatus(status) 29 ctx.Output.SetStatus(status)
23 // first panic from ErrorMaps, is is user defined error functions. 30 // first panic from ErrorMaps, is is user defined error functions.
...@@ -35,14 +42,20 @@ func (ctx *Context) Abort(status int, body string) { ...@@ -35,14 +42,20 @@ func (ctx *Context) Abort(status int, body string) {
35 panic(body) 42 panic(body)
36 } 43 }
37 44
45 // Write string to response body.
46 // it sends response body.
38 func (ctx *Context) WriteString(content string) { 47 func (ctx *Context) WriteString(content string) {
39 ctx.Output.Body([]byte(content)) 48 ctx.Output.Body([]byte(content))
40 } 49 }
41 50
51 // Get cookie from request by a given key.
52 // It's alias of BeegoInput.Cookie.
42 func (ctx *Context) GetCookie(key string) string { 53 func (ctx *Context) GetCookie(key string) string {
43 return ctx.Input.Cookie(key) 54 return ctx.Input.Cookie(key)
44 } 55 }
45 56
57 // Set cookie for response.
58 // It's alias of BeegoOutput.Cookie.
46 func (ctx *Context) SetCookie(name string, value string, others ...interface{}) { 59 func (ctx *Context) SetCookie(name string, value string, others ...interface{}) {
47 ctx.Output.Cookie(name, value, others...) 60 ctx.Output.Cookie(name, value, others...)
48 } 61 }
......
...@@ -10,14 +10,17 @@ import ( ...@@ -10,14 +10,17 @@ import (
10 "github.com/astaxie/beego/session" 10 "github.com/astaxie/beego/session"
11 ) 11 )
12 12
13 // BeegoInput operates the http request header ,data ,cookie and body.
14 // it also contains router params and current session.
13 type BeegoInput struct { 15 type BeegoInput struct {
14 CruSession session.SessionStore 16 CruSession session.SessionStore
15 Params map[string]string 17 Params map[string]string
16 Data map[interface{}]interface{} 18 Data map[interface{}]interface{} // store some values in this context when calling context in filter or controller.
17 Request *http.Request 19 Request *http.Request
18 RequestBody []byte 20 RequestBody []byte
19 } 21 }
20 22
23 // NewInput return BeegoInput generated by http.Request.
21 func NewInput(req *http.Request) *BeegoInput { 24 func NewInput(req *http.Request) *BeegoInput {
22 return &BeegoInput{ 25 return &BeegoInput{
23 Params: make(map[string]string), 26 Params: make(map[string]string),
...@@ -26,22 +29,28 @@ func NewInput(req *http.Request) *BeegoInput { ...@@ -26,22 +29,28 @@ func NewInput(req *http.Request) *BeegoInput {
26 } 29 }
27 } 30 }
28 31
32 // Protocol returns request protocol name, such as HTTP/1.1 .
29 func (input *BeegoInput) Protocol() string { 33 func (input *BeegoInput) Protocol() string {
30 return input.Request.Proto 34 return input.Request.Proto
31 } 35 }
32 36
37 // Uri returns full request url with query string, fragment.
33 func (input *BeegoInput) Uri() string { 38 func (input *BeegoInput) Uri() string {
34 return input.Request.RequestURI 39 return input.Request.RequestURI
35 } 40 }
36 41
42 // Url returns request url path (without query string, fragment).
37 func (input *BeegoInput) Url() string { 43 func (input *BeegoInput) Url() string {
38 return input.Request.URL.String() 44 return input.Request.URL.String()
39 } 45 }
40 46
47 // Site returns base site url as scheme://domain type.
41 func (input *BeegoInput) Site() string { 48 func (input *BeegoInput) Site() string {
42 return input.Scheme() + "://" + input.Domain() 49 return input.Scheme() + "://" + input.Domain()
43 } 50 }
44 51
52 // Scheme returns request scheme as "http" or "https".
53 // if error, return empty string.
45 func (input *BeegoInput) Scheme() string { 54 func (input *BeegoInput) Scheme() string {
46 if input.Request.URL.Scheme != "" { 55 if input.Request.URL.Scheme != "" {
47 return input.Request.URL.Scheme 56 return input.Request.URL.Scheme
...@@ -50,12 +59,17 @@ func (input *BeegoInput) Scheme() string { ...@@ -50,12 +59,17 @@ func (input *BeegoInput) Scheme() string {
50 } else { 59 } else {
51 return "https" 60 return "https"
52 } 61 }
62 return ""
53 } 63 }
54 64
65 // Domain returns host name.
66 // Alias of Host method.
55 func (input *BeegoInput) Domain() string { 67 func (input *BeegoInput) Domain() string {
56 return input.Host() 68 return input.Host()
57 } 69 }
58 70
71 // Host returns host name.
72 // if no host info in request, return localhost.
59 func (input *BeegoInput) Host() string { 73 func (input *BeegoInput) Host() string {
60 if input.Request.Host != "" { 74 if input.Request.Host != "" {
61 hostParts := strings.Split(input.Request.Host, ":") 75 hostParts := strings.Split(input.Request.Host, ":")
...@@ -67,30 +81,39 @@ func (input *BeegoInput) Host() string { ...@@ -67,30 +81,39 @@ func (input *BeegoInput) Host() string {
67 return "localhost" 81 return "localhost"
68 } 82 }
69 83
84 // Method returns http request method.
70 func (input *BeegoInput) Method() string { 85 func (input *BeegoInput) Method() string {
71 return input.Request.Method 86 return input.Request.Method
72 } 87 }
73 88
89 // Is returns boolean of this request is on given method, such as Is("POST").
74 func (input *BeegoInput) Is(method string) bool { 90 func (input *BeegoInput) Is(method string) bool {
75 return input.Method() == method 91 return input.Method() == method
76 } 92 }
77 93
94 // IsAjax returns boolean of this request is generated by ajax.
78 func (input *BeegoInput) IsAjax() bool { 95 func (input *BeegoInput) IsAjax() bool {
79 return input.Header("X-Requested-With") == "XMLHttpRequest" 96 return input.Header("X-Requested-With") == "XMLHttpRequest"
80 } 97 }
81 98
99 // IsSecure returns boolean of this request is in https.
82 func (input *BeegoInput) IsSecure() bool { 100 func (input *BeegoInput) IsSecure() bool {
83 return input.Scheme() == "https" 101 return input.Scheme() == "https"
84 } 102 }
85 103
104 // IsSecure returns boolean of this request is in webSocket.
86 func (input *BeegoInput) IsWebsocket() bool { 105 func (input *BeegoInput) IsWebsocket() bool {
87 return input.Header("Upgrade") == "websocket" 106 return input.Header("Upgrade") == "websocket"
88 } 107 }
89 108
109 // IsSecure returns boolean of whether file uploads in this request or not..
90 func (input *BeegoInput) IsUpload() bool { 110 func (input *BeegoInput) IsUpload() bool {
91 return input.Request.MultipartForm != nil 111 return input.Request.MultipartForm != nil
92 } 112 }
93 113
114 // IP returns request client ip.
115 // if in proxy, return first proxy id.
116 // if error, return 127.0.0.1.
94 func (input *BeegoInput) IP() string { 117 func (input *BeegoInput) IP() string {
95 ips := input.Proxy() 118 ips := input.Proxy()
96 if len(ips) > 0 && ips[0] != "" { 119 if len(ips) > 0 && ips[0] != "" {
...@@ -98,13 +121,14 @@ func (input *BeegoInput) IP() string { ...@@ -98,13 +121,14 @@ func (input *BeegoInput) IP() string {
98 } 121 }
99 ip := strings.Split(input.Request.RemoteAddr, ":") 122 ip := strings.Split(input.Request.RemoteAddr, ":")
100 if len(ip) > 0 { 123 if len(ip) > 0 {
101 if ip[0] != "["{ 124 if ip[0] != "[" {
102 return ip[0] 125 return ip[0]
103 } 126 }
104 } 127 }
105 return "127.0.0.1" 128 return "127.0.0.1"
106 } 129 }
107 130
131 // Proxy returns proxy client ips slice.
108 func (input *BeegoInput) Proxy() []string { 132 func (input *BeegoInput) Proxy() []string {
109 if ips := input.Header("X-Forwarded-For"); ips != "" { 133 if ips := input.Header("X-Forwarded-For"); ips != "" {
110 return strings.Split(ips, ",") 134 return strings.Split(ips, ",")
...@@ -112,15 +136,20 @@ func (input *BeegoInput) Proxy() []string { ...@@ -112,15 +136,20 @@ func (input *BeegoInput) Proxy() []string {
112 return []string{} 136 return []string{}
113 } 137 }
114 138
139 // Refer returns http referer header.
115 func (input *BeegoInput) Refer() string { 140 func (input *BeegoInput) Refer() string {
116 return input.Header("Referer") 141 return input.Header("Referer")
117 } 142 }
118 143
144 // SubDomains returns sub domain string.
145 // if aa.bb.domain.com, returns aa.bb .
119 func (input *BeegoInput) SubDomains() string { 146 func (input *BeegoInput) SubDomains() string {
120 parts := strings.Split(input.Host(), ".") 147 parts := strings.Split(input.Host(), ".")
121 return strings.Join(parts[len(parts)-2:], ".") 148 return strings.Join(parts[len(parts)-2:], ".")
122 } 149 }
123 150
151 // Port returns request client port.
152 // when error or empty, return 80.
124 func (input *BeegoInput) Port() int { 153 func (input *BeegoInput) Port() int {
125 parts := strings.Split(input.Request.Host, ":") 154 parts := strings.Split(input.Request.Host, ":")
126 if len(parts) == 2 { 155 if len(parts) == 2 {
...@@ -130,10 +159,12 @@ func (input *BeegoInput) Port() int { ...@@ -130,10 +159,12 @@ func (input *BeegoInput) Port() int {
130 return 80 159 return 80
131 } 160 }
132 161
162 // UserAgent returns request client user agent string.
133 func (input *BeegoInput) UserAgent() string { 163 func (input *BeegoInput) UserAgent() string {
134 return input.Header("User-Agent") 164 return input.Header("User-Agent")
135 } 165 }
136 166
167 // Param returns router param by a given key.
137 func (input *BeegoInput) Param(key string) string { 168 func (input *BeegoInput) Param(key string) string {
138 if v, ok := input.Params[key]; ok { 169 if v, ok := input.Params[key]; ok {
139 return v 170 return v
...@@ -141,15 +172,19 @@ func (input *BeegoInput) Param(key string) string { ...@@ -141,15 +172,19 @@ func (input *BeegoInput) Param(key string) string {
141 return "" 172 return ""
142 } 173 }
143 174
175 // Query returns input data item string by a given string.
144 func (input *BeegoInput) Query(key string) string { 176 func (input *BeegoInput) Query(key string) string {
145 input.Request.ParseForm() 177 input.Request.ParseForm()
146 return input.Request.Form.Get(key) 178 return input.Request.Form.Get(key)
147 } 179 }
148 180
181 // Header returns request header item string by a given string.
149 func (input *BeegoInput) Header(key string) string { 182 func (input *BeegoInput) Header(key string) string {
150 return input.Request.Header.Get(key) 183 return input.Request.Header.Get(key)
151 } 184 }
152 185
186 // Cookie returns request cookie item string by a given key.
187 // if non-existed, return empty string.
153 func (input *BeegoInput) Cookie(key string) string { 188 func (input *BeegoInput) Cookie(key string) string {
154 ck, err := input.Request.Cookie(key) 189 ck, err := input.Request.Cookie(key)
155 if err != nil { 190 if err != nil {
...@@ -158,10 +193,12 @@ func (input *BeegoInput) Cookie(key string) string { ...@@ -158,10 +193,12 @@ func (input *BeegoInput) Cookie(key string) string {
158 return ck.Value 193 return ck.Value
159 } 194 }
160 195
196 // Session returns current session item value by a given key.
161 func (input *BeegoInput) Session(key interface{}) interface{} { 197 func (input *BeegoInput) Session(key interface{}) interface{} {
162 return input.CruSession.Get(key) 198 return input.CruSession.Get(key)
163 } 199 }
164 200
201 // Body returns the raw request body data as bytes.
165 func (input *BeegoInput) Body() []byte { 202 func (input *BeegoInput) Body() []byte {
166 requestbody, _ := ioutil.ReadAll(input.Request.Body) 203 requestbody, _ := ioutil.ReadAll(input.Request.Body)
167 input.Request.Body.Close() 204 input.Request.Body.Close()
...@@ -171,6 +208,7 @@ func (input *BeegoInput) Body() []byte { ...@@ -171,6 +208,7 @@ func (input *BeegoInput) Body() []byte {
171 return requestbody 208 return requestbody
172 } 209 }
173 210
211 // GetData returns the stored data in this context.
174 func (input *BeegoInput) GetData(key interface{}) interface{} { 212 func (input *BeegoInput) GetData(key interface{}) interface{} {
175 if v, ok := input.Data[key]; ok { 213 if v, ok := input.Data[key]; ok {
176 return v 214 return v
...@@ -178,6 +216,8 @@ func (input *BeegoInput) GetData(key interface{}) interface{} { ...@@ -178,6 +216,8 @@ func (input *BeegoInput) GetData(key interface{}) interface{} {
178 return nil 216 return nil
179 } 217 }
180 218
219 // SetData stores data with given key in this context.
220 // This data are only available in this context.
181 func (input *BeegoInput) SetData(key, val interface{}) { 221 func (input *BeegoInput) SetData(key, val interface{}) {
182 input.Data[key] = val 222 input.Data[key] = val
183 } 223 }
......
...@@ -17,20 +17,27 @@ import ( ...@@ -17,20 +17,27 @@ import (
17 "strings" 17 "strings"
18 ) 18 )
19 19
20 // BeegoOutput does work for sending response header.
20 type BeegoOutput struct { 21 type BeegoOutput struct {
21 Context *Context 22 Context *Context
22 Status int 23 Status int
23 EnableGzip bool 24 EnableGzip bool
24 } 25 }
25 26
27 // NewOutput returns new BeegoOutput.
28 // it contains nothing now.
26 func NewOutput() *BeegoOutput { 29 func NewOutput() *BeegoOutput {
27 return &BeegoOutput{} 30 return &BeegoOutput{}
28 } 31 }
29 32
33 // Header sets response header item string via given key.
30 func (output *BeegoOutput) Header(key, val string) { 34 func (output *BeegoOutput) Header(key, val string) {
31 output.Context.ResponseWriter.Header().Set(key, val) 35 output.Context.ResponseWriter.Header().Set(key, val)
32 } 36 }
33 37
38 // Body sets response body content.
39 // if EnableGzip, compress content string.
40 // it sends out response body directly.
34 func (output *BeegoOutput) Body(content []byte) { 41 func (output *BeegoOutput) Body(content []byte) {
35 output_writer := output.Context.ResponseWriter.(io.Writer) 42 output_writer := output.Context.ResponseWriter.(io.Writer)
36 if output.EnableGzip == true && output.Context.Input.Header("Accept-Encoding") != "" { 43 if output.EnableGzip == true && output.Context.Input.Header("Accept-Encoding") != "" {
...@@ -64,6 +71,8 @@ func (output *BeegoOutput) Body(content []byte) { ...@@ -64,6 +71,8 @@ func (output *BeegoOutput) Body(content []byte) {
64 } 71 }
65 } 72 }
66 73
74 // Cookie sets cookie value via given key.
75 // others are ordered as cookie's max age time, path,domain, secure and httponly.
67 func (output *BeegoOutput) Cookie(name string, value string, others ...interface{}) { 76 func (output *BeegoOutput) Cookie(name string, value string, others ...interface{}) {
68 var b bytes.Buffer 77 var b bytes.Buffer
69 fmt.Fprintf(&b, "%s=%s", sanitizeName(name), sanitizeValue(value)) 78 fmt.Fprintf(&b, "%s=%s", sanitizeName(name), sanitizeValue(value))
...@@ -116,6 +125,8 @@ func sanitizeValue(v string) string { ...@@ -116,6 +125,8 @@ func sanitizeValue(v string) string {
116 return cookieValueSanitizer.Replace(v) 125 return cookieValueSanitizer.Replace(v)
117 } 126 }
118 127
128 // Json writes json to response body.
129 // if coding is true, it converts utf-8 to \u0000 type.
119 func (output *BeegoOutput) Json(data interface{}, hasIndent bool, coding bool) error { 130 func (output *BeegoOutput) Json(data interface{}, hasIndent bool, coding bool) error {
120 output.Header("Content-Type", "application/json;charset=UTF-8") 131 output.Header("Content-Type", "application/json;charset=UTF-8")
121 var content []byte 132 var content []byte
...@@ -136,6 +147,7 @@ func (output *BeegoOutput) Json(data interface{}, hasIndent bool, coding bool) e ...@@ -136,6 +147,7 @@ func (output *BeegoOutput) Json(data interface{}, hasIndent bool, coding bool) e
136 return nil 147 return nil
137 } 148 }
138 149
150 // Jsonp writes jsonp to response body.
139 func (output *BeegoOutput) Jsonp(data interface{}, hasIndent bool) error { 151 func (output *BeegoOutput) Jsonp(data interface{}, hasIndent bool) error {
140 output.Header("Content-Type", "application/javascript;charset=UTF-8") 152 output.Header("Content-Type", "application/javascript;charset=UTF-8")
141 var content []byte 153 var content []byte
...@@ -161,6 +173,7 @@ func (output *BeegoOutput) Jsonp(data interface{}, hasIndent bool) error { ...@@ -161,6 +173,7 @@ func (output *BeegoOutput) Jsonp(data interface{}, hasIndent bool) error {
161 return nil 173 return nil
162 } 174 }
163 175
176 // Xml writes xml string to response body.
164 func (output *BeegoOutput) Xml(data interface{}, hasIndent bool) error { 177 func (output *BeegoOutput) Xml(data interface{}, hasIndent bool) error {
165 output.Header("Content-Type", "application/xml;charset=UTF-8") 178 output.Header("Content-Type", "application/xml;charset=UTF-8")
166 var content []byte 179 var content []byte
...@@ -178,6 +191,8 @@ func (output *BeegoOutput) Xml(data interface{}, hasIndent bool) error { ...@@ -178,6 +191,8 @@ func (output *BeegoOutput) Xml(data interface{}, hasIndent bool) error {
178 return nil 191 return nil
179 } 192 }
180 193
194 // Download forces response for download file.
195 // it prepares the download response header automatically.
181 func (output *BeegoOutput) Download(file string) { 196 func (output *BeegoOutput) Download(file string) {
182 output.Header("Content-Description", "File Transfer") 197 output.Header("Content-Description", "File Transfer")
183 output.Header("Content-Type", "application/octet-stream") 198 output.Header("Content-Type", "application/octet-stream")
...@@ -189,6 +204,8 @@ func (output *BeegoOutput) Download(file string) { ...@@ -189,6 +204,8 @@ func (output *BeegoOutput) Download(file string) {
189 http.ServeFile(output.Context.ResponseWriter, output.Context.Request, file) 204 http.ServeFile(output.Context.ResponseWriter, output.Context.Request, file)
190 } 205 }
191 206
207 // ContentType sets the content type from ext string.
208 // MIME type is given in mime package.
192 func (output *BeegoOutput) ContentType(ext string) { 209 func (output *BeegoOutput) ContentType(ext string) {
193 if !strings.HasPrefix(ext, ".") { 210 if !strings.HasPrefix(ext, ".") {
194 ext = "." + ext 211 ext = "." + ext
...@@ -199,43 +216,63 @@ func (output *BeegoOutput) ContentType(ext string) { ...@@ -199,43 +216,63 @@ func (output *BeegoOutput) ContentType(ext string) {
199 } 216 }
200 } 217 }
201 218
219 // SetStatus sets response status code.
220 // It writes response header directly.
202 func (output *BeegoOutput) SetStatus(status int) { 221 func (output *BeegoOutput) SetStatus(status int) {
203 output.Context.ResponseWriter.WriteHeader(status) 222 output.Context.ResponseWriter.WriteHeader(status)
204 output.Status = status 223 output.Status = status
205 } 224 }
206 225
226 // IsCachable returns boolean of this request is cached.
227 // HTTP 304 means cached.
207 func (output *BeegoOutput) IsCachable(status int) bool { 228 func (output *BeegoOutput) IsCachable(status int) bool {
208 return output.Status >= 200 && output.Status < 300 || output.Status == 304 229 return output.Status >= 200 && output.Status < 300 || output.Status == 304
209 } 230 }
210 231
232 // IsEmpty returns boolean of this request is empty.
233 // HTTP 201,204 and 304 means empty.
211 func (output *BeegoOutput) IsEmpty(status int) bool { 234 func (output *BeegoOutput) IsEmpty(status int) bool {
212 return output.Status == 201 || output.Status == 204 || output.Status == 304 235 return output.Status == 201 || output.Status == 204 || output.Status == 304
213 } 236 }
214 237
238 // IsOk returns boolean of this request runs well.
239 // HTTP 200 means ok.
215 func (output *BeegoOutput) IsOk(status int) bool { 240 func (output *BeegoOutput) IsOk(status int) bool {
216 return output.Status == 200 241 return output.Status == 200
217 } 242 }
218 243
244 // IsSuccessful returns boolean of this request runs successfully.
245 // HTTP 2xx means ok.
219 func (output *BeegoOutput) IsSuccessful(status int) bool { 246 func (output *BeegoOutput) IsSuccessful(status int) bool {
220 return output.Status >= 200 && output.Status < 300 247 return output.Status >= 200 && output.Status < 300
221 } 248 }
222 249
250 // IsRedirect returns boolean of this request is redirection header.
251 // HTTP 301,302,307 means redirection.
223 func (output *BeegoOutput) IsRedirect(status int) bool { 252 func (output *BeegoOutput) IsRedirect(status int) bool {
224 return output.Status == 301 || output.Status == 302 || output.Status == 303 || output.Status == 307 253 return output.Status == 301 || output.Status == 302 || output.Status == 303 || output.Status == 307
225 } 254 }
226 255
256 // IsForbidden returns boolean of this request is forbidden.
257 // HTTP 403 means forbidden.
227 func (output *BeegoOutput) IsForbidden(status int) bool { 258 func (output *BeegoOutput) IsForbidden(status int) bool {
228 return output.Status == 403 259 return output.Status == 403
229 } 260 }
230 261
262 // IsNotFound returns boolean of this request is not found.
263 // HTTP 404 means forbidden.
231 func (output *BeegoOutput) IsNotFound(status int) bool { 264 func (output *BeegoOutput) IsNotFound(status int) bool {
232 return output.Status == 404 265 return output.Status == 404
233 } 266 }
234 267
268 // IsClient returns boolean of this request client sends error data.
269 // HTTP 4xx means forbidden.
235 func (output *BeegoOutput) IsClientError(status int) bool { 270 func (output *BeegoOutput) IsClientError(status int) bool {
236 return output.Status >= 400 && output.Status < 500 271 return output.Status >= 400 && output.Status < 500
237 } 272 }
238 273
274 // IsServerError returns boolean of this server handler errors.
275 // HTTP 5xx means server internal error.
239 func (output *BeegoOutput) IsServerError(status int) bool { 276 func (output *BeegoOutput) IsServerError(status int) bool {
240 return output.Status >= 500 && output.Status < 600 277 return output.Status >= 500 && output.Status < 600
241 } 278 }
...@@ -254,6 +291,7 @@ func stringsToJson(str string) string { ...@@ -254,6 +291,7 @@ func stringsToJson(str string) string {
254 return jsons 291 return jsons
255 } 292 }
256 293
294 // Sessions sets session item value with given key.
257 func (output *BeegoOutput) Session(name interface{}, value interface{}) { 295 func (output *BeegoOutput) Session(name interface{}, value interface{}) {
258 output.Context.Input.CruSession.Set(name, value) 296 output.Context.Input.CruSession.Set(name, value)
259 } 297 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!