Add PUBLIC_IP_SERVICE to netmaker (server).

This commit is contained in:
cameronts 2022-07-26 14:03:51 -07:00
parent fc73a18860
commit 9e5e1b24b4

View file

@ -2,6 +2,7 @@ package servercfg
import (
"errors"
"fmt"
"io"
"net/http"
"os"
@ -427,7 +428,16 @@ func GetPublicIP() (string, error) {
var err error
iplist := []string{"https://ip.server.gravitl.com", "https://ifconfig.me", "https://api.ipify.org", "https://ipinfo.io/ip"}
publicIpService := os.Getenv("PUBLIC_IP_SERVICE")
if publicIpService != "" {
fmt.Println("User provided public IP service is", publicIpService)
// prepend the user-specified service so it's checked first
iplist = append([]string{publicIpService}, iplist...)
}
for _, ipserver := range iplist {
fmt.Println("Running public IP check with service", ipserver)
client := &http.Client{
Timeout: time.Second * 10,
}
@ -442,6 +452,7 @@ func GetPublicIP() (string, error) {
continue
}
endpoint = string(bodyBytes)
fmt.Println("Public IP address is", endpoint)
break
}
}