Files
koin_ping_0.2.0/backend-go/internal/handlers/helpers.go
KS Jannette 5f81a4b1cc crossover
2026-02-27 15:07:43 -05:00

31 lines
604 B
Go

package handlers
import (
"encoding/json"
"net/http"
"strconv"
)
type errorBody struct {
Error string `json:"error"`
Message string `json:"message"`
}
func writeJSON(w http.ResponseWriter, status int, v interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
json.NewEncoder(w).Encode(v)
}
func writeError(w http.ResponseWriter, status int, code, message string) {
writeJSON(w, status, errorBody{Error: code, Message: message})
}
func parseIntParam(s string) (int, bool) {
n, err := strconv.Atoi(s)
if err != nil {
return 0, false
}
return n, true
}