-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathrisk.go
More file actions
42 lines (34 loc) · 658 Bytes
/
risk.go
File metadata and controls
42 lines (34 loc) · 658 Bytes
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
package ipdb
import "strconv"
type RiskInfo struct {
Score int
Behavior string
CountryCode string
}
type Risk struct {
reader *reader
}
func NewRisk(fn string) (*Risk, error) {
r, e := newReader(fn, &RiskInfo{})
if e != nil {
return nil, e
}
return &Risk{reader: r}, nil
}
func (r *Risk) FindInfo(addr string) (*RiskInfo, error) {
info := &RiskInfo{}
m, e := r.reader.FindMap(addr, "CN")
if e != nil {
return info, e
}
if v, ok := m["score"]; ok {
info.Score, _ = strconv.Atoi(v)
}
if v, ok := m["behavior"]; ok {
info.Behavior = v
}
if v, ok := m["country_code"]; ok {
info.CountryCode = v
}
return info, nil
}