dip now get to latest version of geoip databases
This commit is contained in:
parent
3e23f7e872
commit
c09ead8ae0
@ -1,8 +1,10 @@
|
|||||||
package geoip
|
package geoip
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -10,14 +12,36 @@ import (
|
|||||||
geoip2 "github.com/oschwald/geoip2-golang"
|
geoip2 "github.com/oschwald/geoip2-golang"
|
||||||
)
|
)
|
||||||
|
|
||||||
var RootURL = "https://git.paulbsd.com/paulbsd/GeoLite.mmdb/releases/download/%s/%s"
|
type ApiRes struct {
|
||||||
var Version = "2022.06.16"
|
Tag string `json:"tag_name"`
|
||||||
|
}
|
||||||
|
|
||||||
var dbs map[string]string = map[string]string{
|
var RootURL = "https://git.paulbsd.com/paulbsd/GeoLite.mmdb/releases/download/%s/%s"
|
||||||
"city": fmt.Sprintf(RootURL, Version, "GeoLite2-City.mmdb"),
|
var APIUrl = "https://git.paulbsd.com/api/v1/repos/paulbsd/GeoLite.mmdb/releases"
|
||||||
"asn": fmt.Sprintf(RootURL, Version, "GeoLite2-ASN.mmdb")}
|
|
||||||
|
func GetLastVersion() string {
|
||||||
|
var apiresults []ApiRes
|
||||||
|
res, err := http.Get(APIUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(body, &apiresults)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
}
|
||||||
|
return apiresults[0].Tag
|
||||||
|
}
|
||||||
|
|
||||||
func InitGeoIP() (citydb *geoip2.Reader, asndb *geoip2.Reader, err error) {
|
func InitGeoIP() (citydb *geoip2.Reader, asndb *geoip2.Reader, err error) {
|
||||||
|
var version = GetLastVersion()
|
||||||
|
var dbs map[string]string = map[string]string{
|
||||||
|
"city": fmt.Sprintf(RootURL, version, "GeoLite2-City.mmdb"),
|
||||||
|
"asn": fmt.Sprintf(RootURL, version, "GeoLite2-ASN.mmdb")}
|
||||||
|
log.Printf("Fetching GeoLite.mmdb version %s\n", version)
|
||||||
citydb, err = FetchDB(dbs["city"])
|
citydb, err = FetchDB(dbs["city"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user