mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
btest/Files/mmdb: golang-ci suggested fixes
Thanks Benjamin for the hint.
This commit is contained in:
parent
44b67894ac
commit
631b30f5bb
1 changed files with 10 additions and 8 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/maxmind/mmdbwriter/mmdbtype"
|
"github.com/maxmind/mmdbwriter/mmdbtype"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeDb(fname, name string, record mmdbtype.Map, nets ...*net.IPNet) {
|
func writeDB(fname, name string, record mmdbtype.Map, nets ...*net.IPNet) {
|
||||||
writer, err := mmdbwriter.New(
|
writer, err := mmdbwriter.New(
|
||||||
mmdbwriter.Options{
|
mmdbwriter.Options{
|
||||||
DatabaseType: name,
|
DatabaseType: name,
|
||||||
|
@ -31,12 +31,14 @@ func writeDb(fname, name string, record mmdbtype.Map, nets ...*net.IPNet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer fh.Close()
|
|
||||||
|
|
||||||
_, err = writer.WriteTo(fh)
|
_, err = writer.WriteTo(fh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fh.Close()
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fh.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -44,13 +46,13 @@ func main() {
|
||||||
_, net2, _ := net.ParseCIDR("131.243.0.0/16")
|
_, net2, _ := net.ParseCIDR("131.243.0.0/16")
|
||||||
|
|
||||||
// The ASN record.
|
// The ASN record.
|
||||||
asn_record := mmdbtype.Map{}
|
asnRecord := mmdbtype.Map{}
|
||||||
asn_record["autonomous_system_number"] = mmdbtype.Uint32(16)
|
asnRecord["autonomous_system_number"] = mmdbtype.Uint32(16)
|
||||||
asn_record["autonomous_system_organization"] = mmdbtype.String("Lawrence Berkeley National Laboratory")
|
asnRecord["autonomous_system_organization"] = mmdbtype.String("Lawrence Berkeley National Laboratory")
|
||||||
writeDb("GeoLite2-ASN.mmdb", "My-ASN-DB", asn_record, net1, net2)
|
writeDB("GeoLite2-ASN.mmdb", "My-ASN-DB", asnRecord, net1, net2)
|
||||||
|
|
||||||
// The Location record.
|
// The Location record.
|
||||||
loc_record := mmdbtype.Map{
|
locRecord := mmdbtype.Map{
|
||||||
"country": mmdbtype.Map{
|
"country": mmdbtype.Map{
|
||||||
"iso_code": mmdbtype.String("US"),
|
"iso_code": mmdbtype.String("US"),
|
||||||
"names": mmdbtype.Map{
|
"names": mmdbtype.Map{
|
||||||
|
@ -67,5 +69,5 @@ func main() {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
writeDb("GeoLite2-City.mmdb", "My-City-DB", loc_record, net1, net2)
|
writeDB("GeoLite2-City.mmdb", "My-City-DB", locRecord, net1, net2)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue