File tree 2 files changed +5
-21
lines changed
websites/code/studygolang/src
2 files changed +5
-21
lines changed Original file line number Diff line number Diff line change 7
7
package controller
8
8
9
9
import (
10
- "go.net/websocket"
11
- "logger"
12
- "service"
13
10
"strconv"
14
- "strings"
15
11
"sync"
16
12
"time"
13
+
14
+ "go.net/websocket"
15
+ "logger"
16
+ "service"
17
17
"util"
18
18
)
19
19
@@ -30,12 +30,7 @@ func WsHandler(wsConn *websocket.Conn) {
30
30
req := wsConn .Request ()
31
31
user , err := strconv .Atoi (req .FormValue ("uid" ))
32
32
if err != nil || user == 0 {
33
- remoteAddr := req .Header .Get ("Remote_addr" )
34
- if remoteAddr == "" {
35
- remoteAddr = req .RemoteAddr
36
- }
37
- pos := strings .LastIndex (remoteAddr , ":" )
38
- ip := remoteAddr [:pos ]
33
+ ip := util .Ip (req )
39
34
logger .Debugln ("user ip:" , ip )
40
35
user = int (util .Ip2long (ip ))
41
36
}
Original file line number Diff line number Diff line change 7
7
package util
8
8
9
9
import (
10
- "encoding/binary"
11
- "net"
12
10
"strconv"
13
11
"strings"
14
12
)
@@ -30,12 +28,3 @@ func Join(ins []int, sep string) string {
30
28
}
31
29
return strings .Join (strSlice , sep )
32
30
}
33
-
34
- func Ip2long (ipstr string ) uint32 {
35
- ip := net .ParseIP (ipstr )
36
- if ip == nil {
37
- return 0
38
- }
39
- ip = ip .To4 ()
40
- return binary .BigEndian .Uint32 (ip )
41
- }
You can’t perform that action at this time.
0 commit comments