-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontent.go
More file actions
65 lines (52 loc) · 1.62 KB
/
content.go
File metadata and controls
65 lines (52 loc) · 1.62 KB
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
//Copyright
//go mvc web framework
//http content
package gomvc
import (
"net/http"
"net/url"
)
//http context
type HttpContext struct {
Request *http.Request //http request
//Agent string //user agent
Resonse http.ResponseWriter //http response
Method string //http method
RequestPath string //request path
PhysicalPath string //physical Path
URL *url.URL //request url
RemoteAddr string //remote address
//self fields
RouteData map[string]string //route data
Result HttpResult //result
LastError error //last error
User string //user name
Variables map[string]interface{} //server variables
Files string //files uploaded, TODO:
//Session, Cookie, Form, QueryString, Cache//TODO:
}
func (ctx *HttpContext) Value(name string) string {
v, ok := ctx.RouteData[name]
if ok {
return v
}
return ctx.Request.FormValue(name)
}
func (ctx *HttpContext) UserAgent() string {
return ctx.Request.Header.Get("User-Agent")
}
func (ctx *HttpContext) SetHeader(key string, value string) {
ctx.Resonse.Header().Set(key, value)
}
func (ctx *HttpContext) ContentType(ctype string) {
ctx.Resonse.Header().Set("Content-Type", ctype)
}
func (ctx *HttpContext) Status(code int) {
ctx.Resonse.WriteHeader(code)
}
func (ctx *HttpContext) Accept() string {
return ctx.Request.Header.Get("Accept")
}
func (ctx *HttpContext) Write(b []byte) {
ctx.Resonse.Write(b)
}