Browse Source

Match `distance` query parameter behavior with PHP backend

Maddie Zhan 5 years ago
parent
commit
275286cd79
6 changed files with 7 additions and 10 deletions
  1. 2 0
      .gitignore
  2. 0 2
      README.md
  3. 0 1
      config/config.go
  4. 0 2
      settings.toml
  5. 2 2
      web/helpers.go
  6. 3 3
      web/web.go

+ 2 - 0
.gitignore

@@ -1,2 +1,4 @@
 results/idObfuscation_salt.php
 backend/getIP_serverLocation.php
+speedtest.db
+.idea/

+ 0 - 2
README.md

@@ -72,8 +72,6 @@ You need Go 1.13+ to compile the binary.
     download_chunks=4
     # ipinfo.io API key, if applicable
     ipinfo_api_key=""
-    # distance unit used in frontend, available options: M (miles), K (kilometers), N (nautical miles), default is "K"
-    distance_unit="K"
     
     # password for logging into statistics page, change this to enable stats page
     statistics_password="PASSWORD"

+ 0 - 1
config/config.go

@@ -10,7 +10,6 @@ type Config struct {
 	Port           string `mapstructure:"listen_port"`
 	DownloadChunks int    `mapstructure:"download_chunks"`
 	IPInfoAPIKey   string `mapstructure:"ipinfo_api_key"`
-	DistanceUnit   string `mapstructure:"distance_unit"`
 
 	StatsPassword string `mapstructure:"statistics_password"`
 	RedactIP      bool   `mapstructure:"redact_ip_addresses"`

+ 0 - 2
settings.toml

@@ -6,8 +6,6 @@ listen_port=8989
 download_chunks=4
 # ipinfo.io API key, if applicable
 ipinfo_api_key=""
-# distance unit used in frontend, available options: M (miles), K (kilometers), N (nautical miles)
-distance_unit="K"
 
 # password for logging into statistics page
 statistics_password="PASSWORD"

+ 2 - 2
web/helpers.go

@@ -143,10 +143,10 @@ func calculateDistance(clientLocation string, unit string) string {
 
 	unitString := " mi"
 	switch unit {
-	case "K":
+	case "km":
 		dist = dist * 1.609344
 		unitString = " km"
-	case "N":
+	case "NM":
 		dist = dist * 0.8684
 		unitString = " NM"
 	}

+ 3 - 3
web/web.go

@@ -155,7 +155,7 @@ func getIP(w http.ResponseWriter, r *http.Request) {
 	}
 
 	getISPInfo := r.FormValue("isp") == "true"
-	getDistance := r.FormValue("distance") == "true"
+	distanceUnit := r.FormValue("distance")
 
 	ret.ProcessedString = clientIP
 
@@ -174,8 +174,8 @@ func getIP(w http.ResponseWriter, r *http.Request) {
 			isp += ", " + ispInfo.Country
 		}
 
-		if ispInfo.Location != "" && getDistance {
-			isp += " (" + calculateDistance(ispInfo.Location, config.LoadedConfig().DistanceUnit) + ")"
+		if ispInfo.Location != "" {
+			isp += " (" + calculateDistance(ispInfo.Location, distanceUnit) + ")"
 		}
 
 		ret.ProcessedString += " - " + isp