Documentation ¶
Index ¶
- func BadRequestError(w http.ResponseWriter, err error)
- func Error(w http.ResponseWriter, err error, httpStatus int)
- func NotFoundError(w http.ResponseWriter, err error)
- func Ok(w http.ResponseWriter, response interface{}, httpStatus int)
- func ServerError(w http.ResponseWriter, err error)
- func ValidationError(w http.ResponseWriter, err error)
- type ApiError
- type ErrorWrapper
- type Server
- func (s *Server) CreateRoutes()
- func (s *Server) EnableCORS(next http.Handler) http.Handler
- func (s *Server) HandleAddUser() http.HandlerFunc
- func (s *Server) HandleCheckHealth() http.HandlerFunc
- func (s *Server) HandleCheckLive() http.HandlerFunc
- func (s *Server) HandleGetUser() http.HandlerFunc
- func (s *Server) HandleGetUsers() http.HandlerFunc
- func (s *Server) LimitBody(next http.Handler) http.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BadRequestError ¶
func BadRequestError(w http.ResponseWriter, err error)
BadRequestError writes the provided error along with a 400 http status.
func Error ¶
func Error(w http.ResponseWriter, err error, httpStatus int)
Error writes the provided error along with the provided http status.
func NotFoundError ¶
func NotFoundError(w http.ResponseWriter, err error)
NotFoundError writes the provided error along with a 404 http status.
func Ok ¶
func Ok(w http.ResponseWriter, response interface{}, httpStatus int)
Ok encodes to JSON and writes the provided response (if any) along with the httpStatus.
func ServerError ¶
func ServerError(w http.ResponseWriter, err error)
ServerError writes the provided error along with a 500 http status.
func ValidationError ¶
func ValidationError(w http.ResponseWriter, err error)
ValidationError writes the provided error along with a 422 http status. If the error cannot be marshalled, a 500 error is returned instead.
Types ¶
type ErrorWrapper ¶
type ErrorWrapper struct {
Error ApiError `json:"error"`
}
ErrorWrapper wraps an ApiError, so consumers can check for it easier.
type Server ¶
The Server is used as a container for the most important dependencies.
func (*Server) HandleAddUser ¶
func (s *Server) HandleAddUser() http.HandlerFunc
HandleAddUser handles the "POST /users" endpoint.
func (*Server) HandleCheckHealth ¶
func (s *Server) HandleCheckHealth() http.HandlerFunc
HandleCheckHealth is used for checking if the service is healthy.
func (*Server) HandleCheckLive ¶
func (s *Server) HandleCheckLive() http.HandlerFunc
HandleCheckLive is used for checking if the service is up.
func (*Server) HandleGetUser ¶
func (s *Server) HandleGetUser() http.HandlerFunc
HandleGetUser handles the "GET /users/{id}" endpoint.
func (*Server) HandleGetUsers ¶
func (s *Server) HandleGetUsers() http.HandlerFunc
HandleGetUsers handles the "GET /users" endpoint.