-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcustomize.go
82 lines (65 loc) · 1.41 KB
/
customize.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Author Linvon
*/
package main
import (
"fmt"
"sync"
jsoniter "github.com/json-iterator/go"
)
var json = jsoniter.ConfigCompatibleWithStandardLibrary
var gMu sync.Mutex
var allMap, errMap map[string]int64
// TODO Init your global record data
func initData() {
allMap = make(map[string]int64, 0)
errMap = make(map[string]int64, 0)
}
// TODO complete your line process function
func lineProcess(line string) {
// pre process
log, err := UnmarshalLog(line)
if err != nil {
return
}
// post process
// Update Global Data
gMu.Lock()
allMap[log.HDid] ++
if log.HAv != "" {
errMap[log.HDid] ++
}
gMu.Unlock()
}
// TODO Customize your Output format
func outPut() {
s, _ := json.Marshal(allMap)
fmt.Println(string(s))
s, _ = json.Marshal(errMap)
fmt.Println(string(s))
}
// TODO complete process function of unmarshal if needed
func UnmarshalLog(line string) (log LogSt, err error) {
// pre process
err = json.Unmarshal([]byte(line), &log)
if err != nil {
return
}
// post process
return
}
// TODO your LogSt if needed
type LogSt struct {
HAv string `json:"h_av"`
HDt int `json:"h_dt"`
HOs int `json:"h_os"`
HApp string `json:"h_app"`
HModel string `json:"h_model"`
HDid string `json:"h_did"`
HNt int `json:"h_nt"`
HCh string `json:"h_ch"`
HTs int64 `json:"h_ts"`
HLang string `json:"h_lang"`
HPkg string `json:"h_pkg"`
HM int `json:"h_m"`
}