platform: modularize api/gui, add docs-tests-web foundation, and refresh root config
This commit is contained in:
44
selective-vpn-api/app/egress_identity_probe_external.go
Normal file
44
selective-vpn-api/app/egress_identity_probe_external.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
egressutilpkg "selective-vpn-api/app/egressutil"
|
||||
)
|
||||
|
||||
func egressProbeExternalIP() (string, error) {
|
||||
endpoints := egressIPEndpoints()
|
||||
ip, errs := egressutilpkg.ProbeFirstSuccess(endpoints, func(rawURL string) (string, error) {
|
||||
body, err := egressutilpkg.HTTPGetBody(egressHTTPClient, rawURL, egressIdentityProbeTimeout, "selective-vpn-api/egress-identity", 8*1024)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return egressutilpkg.ParseIPFromBody(body)
|
||||
})
|
||||
if strings.TrimSpace(ip) != "" {
|
||||
return ip, nil
|
||||
}
|
||||
if len(errs) == 0 {
|
||||
return "", fmt.Errorf("egress probe endpoints are not configured")
|
||||
}
|
||||
return "", fmt.Errorf("%s", strings.Join(errs, "; "))
|
||||
}
|
||||
|
||||
func egressProbeExternalIPViaInterface(iface string) (string, error) {
|
||||
iface = strings.TrimSpace(iface)
|
||||
if iface == "" {
|
||||
return egressProbeExternalIP()
|
||||
}
|
||||
endpoints := egressIPEndpoints()
|
||||
ip, errs := egressutilpkg.ProbeFirstSuccess(endpoints, func(rawURL string) (string, error) {
|
||||
return egressProbeURLViaInterface(rawURL, iface, egressIdentityProbeTimeout)
|
||||
})
|
||||
if strings.TrimSpace(ip) != "" {
|
||||
return ip, nil
|
||||
}
|
||||
if len(errs) == 0 {
|
||||
return "", fmt.Errorf("egress probe endpoints are not configured")
|
||||
}
|
||||
return "", fmt.Errorf("%s", strings.Join(errs, "; "))
|
||||
}
|
||||
Reference in New Issue
Block a user