Compare commits
2 Commits
e05c3a06ae
...
v0.0.24
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa900d5e3b | ||
|
|
91cb3a48f8 |
10
env/enviroment.go
vendored
10
env/enviroment.go
vendored
@@ -26,11 +26,13 @@ func Load(path string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (key EnvKey) GetValue() string {
|
func (key EnvKey) GetValue() string {
|
||||||
port := os.Getenv(string(key))
|
keyStr := string(key)
|
||||||
if port == "" {
|
value := os.Getenv(keyStr)
|
||||||
port = "8080"
|
if key == Port && value == "" {
|
||||||
|
value = "8080"
|
||||||
}
|
}
|
||||||
return port
|
|
||||||
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (key EnvKey) SetValue(value string) {
|
func (key EnvKey) SetValue(value string) {
|
||||||
|
|||||||
@@ -20,15 +20,24 @@ func GetLocalIP() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getActiveIP() string {
|
func getActiveIP() string {
|
||||||
conn, err := net.Dial("udp", "8.8.8.8:80")
|
addrs, err := net.InterfaceAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
addr := conn.LocalAddr()
|
for _, address := range addrs {
|
||||||
if udpAddr, ok := addr.(*net.UDPAddr); ok {
|
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||||
return udpAddr.IP.String()
|
|
||||||
|
if ipnet.IP.To4() != nil {
|
||||||
|
ipStr := ipnet.IP.String()
|
||||||
|
|
||||||
|
if ipnet.IP.IsLinkLocalUnicast() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return ipStr
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user