-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (50 loc) · 1.23 KB
/
main.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
61
package main
import (
"fmt"
"github.com/gorilla/websocket"
"net/http"
"time"
)
var (
whitelistFileName string = `whitelist.txt`
whitelistFileFinal string
version = `v1.0.0`
timeStart = time.Now().Round(time.Second)
sessionMap = make(map[uint64]*map[uint64]bool)
sessionChan = make(map[uint64]*chan uint64)
tailBind = make(chan sessionInfo, 1000)
filePool = make(map[uint64]*fileContent)
fileMap = make(map[string]uint64)
httpListen = `:58888`
buffLen = 4096
writeWait time.Duration
fileAllow map[string]bool
sessionSerial uint64
fileSerial uint64
transOut uint64 = 0
noopInterval int64 = 25
iWriteWait int64 = 10
upgrader = websocket.Upgrader{
ReadBufferSize: 4096,
WriteBufferSize: 4096,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
)
func main() {
loadConfig()
go refreshWhiteList()
go manager()
http.HandleFunc(`/ws/status`, statusPage)
http.HandleFunc(`/ws/tail`, serveWs)
http.HandleFunc(`/ws/config`, configPage)
fmt.Println(`WsTail started`)
err := http.ListenAndServe(httpListen, nil)
if err != nil {
panic("ListenAndServe fail: " + err.Error())
}
}
func writeHttp(w http.ResponseWriter, s string) {
w.Write([]byte(s))
}