-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext.go
60 lines (48 loc) · 1.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
package gos
import (
"fmt"
"net/http"
"github.com/tomasen/realip"
)
type Context struct {
*http.Request
mux *Mux
params map[string]string
//data interface{}
//headerSets http.Header
//httpStatus int
Printer
}
func (c *Context) RealIp() string {
return realip.FromRequest(c.Request)
}
func (c *Context) IsTLS() bool {
return c.TLS != nil
}
func (c *Context) Scheme() string {
if c.IsTLS() {
return "https"
}
if scheme := c.Header.Get(HeaderXForwardedProto); scheme != "" {
return scheme
}
if scheme := c.Header.Get(HeaderXForwardedProtocol); scheme != "" {
return scheme
}
if ssl := c.Header.Get(HeaderXForwardedSsl); ssl == "on" {
return "https"
}
if scheme := c.Header.Get(HeaderXUrlScheme); scheme != "" {
return scheme
}
return "http"
}
func (c *Context) AbsURL() string {
return fmt.Sprintf("%s://%s%s", c.Scheme(), c.Host, c.URL.String())
}
func (c *Context) MapBad(code, format string, args ...interface{}) *Map {
return MapStatus(http.StatusBadRequest).Basic(code, format, args...)
}
func (c *Context) MapUnhandled(code, format string, args ...interface{}) *Map {
return MapStatus(http.StatusInternalServerError).Basic(code, format, args...)
}