Make Server-Location configurable
This commit is contained in:
parent
9212301af6
commit
044b913bd5
|
@ -6,9 +6,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
BindAddress string `mapstructure:"bind_address"`
|
BindAddress string `mapstructure:"bind_address"`
|
||||||
Port string `mapstructure:"listen_port"`
|
Port string `mapstructure:"listen_port"`
|
||||||
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
|
ServerLat float64 `mapstructure:"server_lat"`
|
||||||
|
ServerLng float64 `mapstructure:"server_lng"`
|
||||||
|
IPInfoAPIKey string `mapstructure:"ipinfo_api_key"`
|
||||||
|
|
||||||
StatsPassword string `mapstructure:"statistics_password"`
|
StatsPassword string `mapstructure:"statistics_password"`
|
||||||
RedactIP bool `mapstructure:"redact_ip_addresses"`
|
RedactIP bool `mapstructure:"redact_ip_addresses"`
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
bind_address=""
|
bind_address=""
|
||||||
# backend listen port
|
# backend listen port
|
||||||
listen_port=8989
|
listen_port=8989
|
||||||
|
# Server location
|
||||||
|
server_lat=0
|
||||||
|
server_lng=0
|
||||||
# ipinfo.io API key, if applicable
|
# ipinfo.io API key, if applicable
|
||||||
ipinfo_api_key=""
|
ipinfo_api_key=""
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,13 @@ func getIPInfo(addr string) results.IPInfoResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getServerLocation() (float64, float64) {
|
func getServerLocation() (float64, float64) {
|
||||||
|
conf := config.LoadedConfig()
|
||||||
|
|
||||||
|
if conf.ServerLat > 0 && conf.ServerLng > 0 {
|
||||||
|
log.Infof("Configured server coordinates: %.6f, %.6f", conf.ServerLat, conf.ServerLng)
|
||||||
|
return conf.ServerLat, conf.ServerLng
|
||||||
|
}
|
||||||
|
|
||||||
var ret results.IPInfoResponse
|
var ret results.IPInfoResponse
|
||||||
resp, err := http.DefaultClient.Get(getIPInfoURL(""))
|
resp, err := http.DefaultClient.Get(getIPInfoURL(""))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue