wireguard-dashboard/utils/network.go

28 lines
538 B
Go
Raw Permalink Normal View History

2024-03-07 17:07:41 +08:00
package utils
import (
"gitee.ltd/lxh/logger/log"
"wireguard-dashboard/client"
)
type network struct{}
func Network() network {
return network{}
}
// GetHostPublicIP
// @description: 获取本机公网地址
// @receiver network
// @return string
func (network) GetHostPublicIP() string {
var response = map[string]string{}
_, err := client.HttpClient.R().SetResult(&response).Get("https://httpbin.org/ip")
if err != nil {
log.Errorf("获取本机公网IP失败: %v", err.Error())
return ""
}
return response["origin"]
}