From 01ec91df04b079246434952a5d8f34c6d4e3914b Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 31 Aug 2021 21:32:55 +0200 Subject: [feat] make api configurable --- main.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 811e737..0c21c7c 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,13 @@ import ( "github.com/tidwall/cities" ) +const ( + // The config file is also exposed on the top-level + // domain, which is served behind a letsencrypt certificate. this saves passing + // the certificate for the ca etc. + apiForRiseup = "https://black.riseup.net" +) + func floatToString(num float64) string { return strconv.FormatFloat(num, 'f', 6, 64) } @@ -213,6 +220,7 @@ func main() { var port = flag.Int("port", 9001, "port where the service listens on") var metricsPort = flag.Int("metricsPort", 9002, "port where the metrics server listens on") var dbpath = flag.String("geodb", "/var/lib/GeoIP/GeoLite2-City.mmdb", "path to the GeoLite2-City database") + var api = flag.String("api", "", "API to fetch eip-service.json from (default: black.riseup.net)") var notls = flag.Bool("notls", false, "disable TLS on the service") var key = flag.String("server_key", "", "path to the key file for TLS") var crt = flag.String("server_crt", "", "path to the cert file for TLS") @@ -234,6 +242,13 @@ func main() { } } + var configuredAPI string + if *api == "" { + configuredAPI = apiForRiseup + } else { + configuredAPI = "https://" + *api + } + db, err := geoip2.Open(*dbpath) if err != nil { log.Fatal(err) @@ -244,7 +259,7 @@ func main() { geoipdb := geodb{db, forbidden, nil, nil, nil, &earth} log.Println("Seeding gateway list...") - bonafide := newBonafide() + bonafide := newBonafide(configuredAPI) bonafide.getGateways() geoipdb.geolocateGateways(bonafide) -- cgit v1.2.3