diff --git a/env/enviroment.go b/env/enviroment.go index 5564244..d81fb5c 100644 --- a/env/enviroment.go +++ b/env/enviroment.go @@ -26,7 +26,11 @@ func Load(path string) error { } func (key EnvKey) GetValue() string { - return os.Getenv(string(key)) + port := os.Getenv(string(key)) + if port == "" { + port = "8080" + } + return port } func (key EnvKey) SetValue(value string) { diff --git a/handlers/infos.go b/handlers/infos.go index 4062ebb..3b28a4f 100644 --- a/handlers/infos.go +++ b/handlers/infos.go @@ -35,19 +35,10 @@ func getActiveIP() string { 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)