package updates

This commit is contained in:
Greg Gauthier 2023-12-13 12:00:28 +00:00
parent d0a8fdfb11
commit c2508127b4

View File

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"log" "log"
"math/rand" "math/rand"
"net" "net"
@ -22,7 +23,7 @@ type stationRecord struct {
} }
func RandomIP(iplist []net.IP) net.IP { func RandomIP(iplist []net.IP) net.IP {
rand.Seed(time.Now().Unix()) rand.NewSource(time.Now().Unix())
randomIndex := rand.Intn(len(iplist)) randomIndex := rand.Intn(len(iplist))
return iplist[randomIndex] return iplist[randomIndex]
} }
@ -50,7 +51,12 @@ func GetStations(qstring string) ([]stationRecord, error){
if err != nil { if err != nil {
log.Print(err.Error()) log.Print(err.Error())
} }
defer resp.Body.Close() defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Print(err.Error())
}
}(resp.Body)
var data []stationRecord var data []stationRecord
err = json.NewDecoder(resp.Body).Decode(&data) err = json.NewDecoder(resp.Body).Decode(&data)
@ -95,5 +101,3 @@ func StationSearch(name string, country string, state string, tags string, notok
prunedStations := pruneStations(stations) // eliminate stations that are reporting down. prunedStations := pruneStations(stations) // eliminate stations that are reporting down.
return prunedStations, err return prunedStations, err
} }