Created
January 8, 2020 04:27
-
-
Save khsing/bb120f90ae166eba5fe245c23fa3c220 to your computer and use it in GitHub Desktop.
geoip_data_path.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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