Skip to content

Instantly share code, notes, and snippets.

@khsing
Created January 8, 2020 04:27
Show Gist options
  • Save khsing/bb120f90ae166eba5fe245c23fa3c220 to your computer and use it in GitHub Desktop.
Save khsing/bb120f90ae166eba5fe245c23fa3c220 to your computer and use it in GitHub Desktop.
geoip_data_path.diff
diff --git a/infra/conf/router.go b/infra/conf/router.go
index b3870e45..56e71930 100644
--- a/infra/conf/router.go
+++ b/infra/conf/router.go
@@ -1,6 +1,8 @@
package conf
import (
+ "os"
+ "path/filepath"
"encoding/json"
"strconv"
"strings"
@@ -142,7 +144,18 @@ func ParseIP(s string) (*router.CIDR, error) {
}
}
+func fileExists(file string) bool {
+ info, err := os.Stat(file)
+ return err == nil && !info.IsDir()
+}
+
func loadGeoIP(country string) ([]*router.CIDR, error) {
+ if workingDir, err := os.Getwd(); err == nil {
+ geoipData := filepath.Join(workingDir, "geoip.dat")
+ if fileExists(geoipData) {
+ return loadIP(geoipData, country)
+ }
+ }
return loadIP("geoip.dat", country)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment