-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
42 lines (36 loc) · 789 Bytes
/
util.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
package jumper
import (
"net/http"
"strings"
)
type Params map[string]interface{}
func getHost(r *http.Request) string {
IPAddress := r.Header.Get("X-Real-Ip")
if IPAddress == "" {
IPAddress = r.Header.Get("X-Forwarded-For")
}
if IPAddress == "" {
IPAddress = r.RemoteAddr
}
lIndex := strings.LastIndex(IPAddress,":")
if lIndex != -1 {
return string([]rune(IPAddress)[0:lIndex])
}else {
return string([]rune(IPAddress)[0:])
}
}
func getPort(r *http.Request) string {
IPAddress := r.Header.Get("X-Real-Ip")
if IPAddress == "" {
IPAddress = r.Header.Get("X-Forwarded-For")
}
if IPAddress == "" {
IPAddress = r.RemoteAddr
}
lIndex := strings.LastIndex(IPAddress,":")
if lIndex != -1 {
return string([]rune(IPAddress)[lIndex+1:])
}else {
return ""
}
}