country-geo-locations/api/v1/renderer.go

40 lines
804 B
Go
Raw Normal View History

2024-11-26 13:35:54 +01:00
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)
}
}