moved server main to cmd/server

This commit is contained in:
2026-05-07 10:51:21 -06:00
parent 0deb1961fe
commit 5eafd202af
8 changed files with 1 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
package main
import (
"encoding/json"
"net/http"
)
func respondWithError(w http.ResponseWriter, code int, msg string) {
type returnVals struct {
Error string `json:"error"`
}
respondWithJSON(w, code, returnVals{Error: msg})
}
func respondWithJSON(w http.ResponseWriter, code int, payload any) {
dat, err := json.Marshal(payload)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
_, _ = w.Write(dat)
}