-
Notifications
You must be signed in to change notification settings - Fork 0
/
websocket.go
51 lines (43 loc) · 973 Bytes
/
websocket.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
package logger
import (
"github.com/gorilla/websocket"
"golang.org/x/sync/syncmap"
"net/http"
"time"
)
var blackList syncmap.Map
var blackListCopy []string
var OperateLogSocketClient *websocket.Conn
var SystemLogSocketClient *websocket.Conn
var SocketClient = websocket.Upgrader{
HandshakeTimeout: 30 * time.Second,
ReadBufferSize: 2048,
WriteBufferSize: 2048,
WriteBufferPool: nil,
Subprotocols: nil,
Error: nil,
CheckOrigin: nil,
EnableCompression: false,
}
func checkOrigin(req *http.Request) bool {
if _, ok := blackList.Load(req.RemoteAddr); ok {
return false
}
return true
}
func ReadBlackList() []string {
return blackListCopy
}
func AddBlackList(ip string) {
var temp []string
blackList.Store(ip, true)
blackList.Range(func(key, value interface{}) bool {
v, _ := value.(string)
temp = append(temp, v)
return true
})
blackListCopy = temp
}
func DeleteBlackList(ip string) {
blackList.Delete(ip)
}