File tree Expand file tree Collapse file tree 2 files changed +51
-20
lines changed Expand file tree Collapse file tree 2 files changed +51
-20
lines changed Original file line number Diff line number Diff line change @@ -46,8 +46,12 @@ func (p *proxy) admin(w http.ResponseWriter, r *http.Request) {
46
46
}
47
47
newData = newData + service + "=>" + newUrl + "\n "
48
48
}
49
+ ip := ClientIP (r )
50
+ if ip != "" {
51
+ ip = "本机IP[" + ip + "]<br>"
52
+ }
49
53
w .Header ().Set ("Content-Type" , "text/html;charset=utf-8" )
50
- w .Write ([]byte ("<html><head><title>开发联调神器</title></head><form method=\" POST\" ><center>开发联调神器(保存前先刷新 )<br><textarea placeholder=\" test=>192.168.8.8:8080\r \n 效果:\r \n " + GetURL (r ) + "/test/product/list => http://192.168.8.8:8080/product/list\" autofocus name=\" data\" rows=\" 30\" cols=\" 100\" >" + newData + "</textarea><br><input type=\" submit\" value=\" 提交\" ></center></form><html>" ))
54
+ w .Write ([]byte ("<html><head><title>开发联调神器</title></head><form method=\" POST\" ><center>开发联调神器(先刷新再保存 )<br>" + ip + " <textarea placeholder=\" test=>192.168.8.8:8080\r \n 效果:\r \n " + GetURL (r ) + "/test/product/list => http://192.168.8.8:8080/product/list\" autofocus name=\" data\" rows=\" 30\" cols=\" 100\" >" + newData + "</textarea><br><input type=\" submit\" value=\" 提交\" ></center></form><html>" ))
51
55
}
52
56
53
57
func (p * proxy ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
@@ -91,23 +95,4 @@ func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
91
95
proxy .ServeHTTP (w , r )
92
96
}
93
97
94
- //获取url中的第一个参数
95
- func singleJoiningSlash (a , b string ) string {
96
- aslash := strings .HasSuffix (a , "/" )
97
- bslash := strings .HasPrefix (b , "/" )
98
- switch {
99
- case aslash && bslash :
100
- return a + b [1 :]
101
- case ! aslash && ! bslash :
102
- return a + "/" + b
103
- }
104
- return a + b
105
- }
106
98
107
- func GetURL (r * http.Request ) (Url string ) {
108
- scheme := "http://"
109
- if r .TLS != nil {
110
- scheme = "https://"
111
- }
112
- return strings .Join ([]string {scheme , r .Host }, "" )
113
- }
Original file line number Diff line number Diff line change
1
+ package dev
2
+
3
+ import (
4
+ "net"
5
+ "net/http"
6
+ "strings"
7
+ )
8
+
9
+ //获取url中的第一个参数
10
+ func singleJoiningSlash (a , b string ) string {
11
+ aslash := strings .HasSuffix (a , "/" )
12
+ bslash := strings .HasPrefix (b , "/" )
13
+ switch {
14
+ case aslash && bslash :
15
+ return a + b [1 :]
16
+ case ! aslash && ! bslash :
17
+ return a + "/" + b
18
+ }
19
+ return a + b
20
+ }
21
+
22
+ //获取协议
23
+ func GetURL (r * http.Request ) (Url string ) {
24
+ scheme := "http://"
25
+ if r .TLS != nil {
26
+ scheme = "https://"
27
+ }
28
+ return strings .Join ([]string {scheme , r .Host }, "" )
29
+ }
30
+
31
+ //获取ClientIP
32
+ func ClientIP (r * http.Request ) string {
33
+ xForwardedFor := r .Header .Get ("X-Forwarded-For" )
34
+ ip := strings .TrimSpace (strings .Split (xForwardedFor , "," )[0 ])
35
+ if ip != "" {
36
+ return ip
37
+ }
38
+ ip = strings .TrimSpace (r .Header .Get ("X-Real-Ip" ))
39
+ if ip != "" {
40
+ return ip
41
+ }
42
+ if ip , _ , err := net .SplitHostPort (strings .TrimSpace (r .RemoteAddr )); err == nil {
43
+ return ip
44
+ }
45
+ return ""
46
+ }
You can’t perform that action at this time.
0 commit comments