mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 23:26:38 +08:00
feat(agent): embed GeoLite2 City database
Initialize missing Country and City databases from embedded assets and use FyraLabs releases for periodic updates.
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 63 MiB |
@@ -1,12 +1,16 @@
|
||||
// Package geoipdata embeds the default MaxMind GeoLite2 country database.
|
||||
// Package geoipdata embeds the default MaxMind GeoLite2 databases.
|
||||
package geoipdata
|
||||
|
||||
import "embed"
|
||||
|
||||
// FS holds the embedded GeoLite2-Country.mmdb database.
|
||||
// FS holds the embedded GeoLite2 Country and City databases.
|
||||
//
|
||||
//go:embed GeoLite2-Country.mmdb
|
||||
//go:embed GeoLite2-Country.mmdb GeoLite2-City.mmdb
|
||||
var FS embed.FS
|
||||
|
||||
// DefaultMMDBName is the filename of the embedded MaxMind country database.
|
||||
const DefaultMMDBName = "GeoLite2-Country.mmdb"
|
||||
const (
|
||||
// DefaultMMDBName is the filename of the embedded MaxMind Country database.
|
||||
DefaultMMDBName = "GeoLite2-Country.mmdb"
|
||||
// DefaultCityMMDBName is the filename of the embedded MaxMind City database.
|
||||
DefaultCityMMDBName = "GeoLite2-City.mmdb"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package geoipdata
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
)
|
||||
|
||||
func TestEmbeddedDatabasesAreValid(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
filename string
|
||||
databaseTypePart string
|
||||
}{
|
||||
{name: "Country", filename: DefaultMMDBName, databaseTypePart: "Country"},
|
||||
{name: "City", filename: DefaultCityMMDBName, databaseTypePart: "City"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
data, err := fs.ReadFile(FS, test.filename)
|
||||
if err != nil {
|
||||
t.Fatalf("read embedded database: %v", err)
|
||||
}
|
||||
reader, err := maxminddb.FromBytes(data)
|
||||
if err != nil {
|
||||
t.Fatalf("open embedded database: %v", err)
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
if !strings.Contains(reader.Metadata.DatabaseType, test.databaseTypePart) {
|
||||
t.Fatalf("unexpected database type %q", reader.Metadata.DatabaseType)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user