major refactor of main.go

This commit is contained in:
2026-02-18 15:35:56 -08:00
parent be7e8a3c33
commit b49349eb26
8 changed files with 366 additions and 282 deletions
+32
View File
@@ -0,0 +1,32 @@
package handlers
import (
"encoding/json"
"go-weather/models"
"net/http"
)
func Health(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(models.HealthResponse{Status: "ok"})
}
func LatestTemperature(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(models.LatestTemperatureResponse{Temp: 69})
}
func Test(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(models.TestResponse{Status: "hello from go"})
}