mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 02:18:44 -07:00
ba6ac2f604
This adds a small package `geoip` which knows how to download and manage the Maxmind GeoLite2 database we use. This removes the need for various scripts to download and manage the geoip database, something that today happens on Docker startup for the relay pool server and using various hand written hacks for the usage reporting server. The database is downloaded when needed and then refreshed on a best-effort basis weekly.
37 lines
774 B
Go
37 lines
774 B
Go
// Copyright (C) 2024 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package geoip
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func TestDownloadAndOpen(t *testing.T) {
|
|
acctID, _ := strconv.Atoi(os.Getenv("GEOIP_ACCOUNT_ID"))
|
|
if acctID == 0 {
|
|
t.Skip("No account ID set")
|
|
}
|
|
license := os.Getenv("GEOIP_LICENSE_KEY")
|
|
if license == "" {
|
|
t.Skip("No license key set")
|
|
}
|
|
|
|
p, err := NewGeoLite2CityProvider(context.Background(), acctID, license, t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, err = p.City(net.ParseIP("8.8.8.8"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|