33 lines
957 B
Go
33 lines
957 B
Go
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"})
|
|
}
|