From c195f6b03751bbb4012f48b57b5961a10d4d4113 Mon Sep 17 00:00:00 2001 From: "kali kaneko (leap communications)" Date: Tue, 15 Feb 2022 23:15:15 +0100 Subject: fix blank gateway array i really should start asking someone for code reviews, or committing only after a coffee. this yolo attitude is no good for anyone. this was a silly typo on db98de9. I guess I write write err != nil too much... --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 07a1ba5..5f7a66b 100644 --- a/main.go +++ b/main.go @@ -183,11 +183,14 @@ type GeolocationJSON struct { func (jh *jsonHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { ipstr := getRemoteIP(req) - record, err := jh.geoipdb.getRecordForIP(ipstr) sortedGateways := []string{""} - if err != nil { + + record, err := jh.geoipdb.getRecordForIP(ipstr) + if err == nil { sortedGateways = jh.geoipdb.sortGateways(record.Location.Latitude, record.Location.Longitude) hitsPerCountry.With(prometheus.Labels{"country": record.Country.IsoCode}).Inc() + } else { + log.Println("error while getting record for", ipstr) } data := &GeolocationJSON{ ipstr, -- cgit v1.2.3