country-geo-locations/api/v1/renderer.go
Tom Neuber 8215e1f13a
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful
refactor: restructure project
2024-11-26 13:35:54 +01:00

39 lines
804 B
Go

package apiv1
import (
"log"
"net/http"
"github.com/go-chi/render"
)
func errNotFound() render.Renderer {
return &errResponse{
HTTPStatusCode: http.StatusNotFound,
StatusText: "Resource not found",
}
}
func errInvalidRequest(err error) render.Renderer {
return &errResponse{
Err: err,
HTTPStatusCode: http.StatusBadRequest,
StatusText: "Invalid request",
ErrorText: err.Error(),
}
}
func errRender(err error) render.Renderer {
return &errResponse{
Err: err,
HTTPStatusCode: http.StatusUnprocessableEntity,
StatusText: "Error rendering response",
ErrorText: err.Error(),
}
}
func renderResponse(w http.ResponseWriter, r *http.Request, v render.Renderer) {
if err := render.Render(w, r, v); err != nil {
log.Fatal(err)
}
}