-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontext.go
35 lines (31 loc) · 1.33 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
package fireball
import (
"net/http"
)
var (
HTMLHeaders = map[string]string{"Content-Type": "text/html"}
JSONHeaders = map[string]string{"Content-Type": "application/json"}
TextHeaders = map[string]string{"Content-Type": "text/plain"}
CORSHeaders = map[string]string{
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Headers": "Authorization, Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers",
"Access-Control-Allow-Methods": "GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, CONNECT, TRACE, PURGE",
}
)
// Context is passed into Handlers
// It contains fields and helper functions related to the request
type Context struct {
// PathVariables are the URL-related variables returned by the Router
PathVariables map[string]string
// Meta can be used to pass information along Decorators
Meta map[string]interface{}
// Parser is used to render html templates
Parser TemplateParser
// Request is the originating *http.Request
Request *http.Request
}
// Context.HTML calls HTML with the Context's template parser
func (c *Context) HTML(status int, templateName string, data interface{}) (*HTTPResponse, error) {
return HTML(c.Parser, status, templateName, data)
}