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