-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.go
44 lines (37 loc) · 891 Bytes
/
stats.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
package main
import (
"fmt"
"os"
"strconv"
"time"
)
func initStats() map[string]int {
statsListMapBuffer := make(map[string]int)
//statsListMap["target hit"] = 0
go statsLog()
return statsListMapBuffer
}
func hitTarget(ipAddress string) {
value, exist := statsListMap[ipAddress]
if exist == false {
statsListMap[ipAddress] = 1
return
}
statsListMap[ipAddress] = value + 1
return
}
func statsLog() {
f, err := os.OpenFile("log.txt", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0644)
//f, err := os.OpenFile("log.txt", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
defer f.Close()
if err != nil {
panic(err)
}
f.WriteString(time.Now().Format("2006-01-02 15:04:05") + "\n")
for one := range statsListMap {
f.WriteString(one + "\t " + strconv.Itoa(statsListMap[one]) + "\n")
}
fmt.Println("Write current stats: ", statsListMap)
time.Sleep(time.Minute * 1)
statsLog()
}