mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 18:08:14 -05:00
27 lines
562 B
Go
27 lines
562 B
Go
package hy
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/oschwald/geoip2-golang"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func loadMMDBReader(filename string) (*geoip2.Reader, error) {
|
|
if _, err := os.Stat(filename); err != nil {
|
|
if os.IsNotExist(err) {
|
|
logrus.Info("GeoLite2 database not found, downloading...")
|
|
logrus.WithFields(logrus.Fields{
|
|
"file": filename,
|
|
}).Info("GeoLite2 database downloaded")
|
|
return geoip2.Open(filename)
|
|
} else {
|
|
// some other error
|
|
return nil, err
|
|
}
|
|
} else {
|
|
// file exists, just open it
|
|
return geoip2.Open(filename)
|
|
}
|
|
}
|