Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa900d5e3b | ||
|
|
91cb3a48f8 | ||
|
|
e05c3a06ae |
2
.env
2
.env
@@ -1,5 +1,5 @@
|
||||
#empty|development|debug
|
||||
ENV=
|
||||
ENV=
|
||||
PHOTO_DIR=images
|
||||
HOST=0.0.0.0
|
||||
PORT=8080
|
||||
|
||||
8
env/enviroment.go
vendored
8
env/enviroment.go
vendored
@@ -26,7 +26,13 @@ func Load(path string) error {
|
||||
}
|
||||
|
||||
func (key EnvKey) GetValue() string {
|
||||
return os.Getenv(string(key))
|
||||
keyStr := string(key)
|
||||
value := os.Getenv(keyStr)
|
||||
if key == Port && value == "" {
|
||||
value = "8080"
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
func (key EnvKey) SetValue(value string) {
|
||||
|
||||
@@ -20,34 +20,34 @@ 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 ""
|
||||
}
|
||||
|
||||
func InfoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
port := env.Port.GetValue()
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
speed := env.IntervalDefault.GetValue()
|
||||
if speed == "" {
|
||||
speed = "10"
|
||||
}
|
||||
|
||||
data := map[string]string{
|
||||
"ip": GetLocalIP(),
|
||||
"port": port,
|
||||
"port": env.Port.GetValue(),
|
||||
"speed": GetInterval(),
|
||||
}
|
||||
err := json.NewEncoder(w).Encode(data)
|
||||
|
||||
Reference in New Issue
Block a user