Documentation ¶
Index ¶
- type API
- func (api *API) ErrorResponse(w http.ResponseWriter, r *http.Request, status int, message interface{})
- func (api *API) GetIpHandler(w http.ResponseWriter, r *http.Request)
- func (api *API) GetIpInfoHandler(w http.ResponseWriter, r *http.Request)
- func (api *API) HealthcheckHandler(w http.ResponseWriter, r *http.Request)
- func (api *API) LogError(r *http.Request, err error)
- func (api *API) MethodNotAllowedResponse(w http.ResponseWriter, r *http.Request)
- func (api *API) NotFoundResponse(w http.ResponseWriter, r *http.Request)
- func (api *API) Routes() http.Handler
- func (api *API) Serve() error
- func (api *API) ServerErrorResponse(w http.ResponseWriter, r *http.Request, err error)
- func (api *API) WriteJSON(w http.ResponseWriter, status int, data Envelope, headers http.Header) error
- func (api *API) WritePlainText(w http.ResponseWriter, status int, body string, headers http.Header) error
- type Config
- type Envelope
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
func (*API) ErrorResponse ¶
func (api *API) ErrorResponse(w http.ResponseWriter, r *http.Request, status int, message interface{})
The errorResponse() method is a generic helper for sending JSON-formatted error messages to the client with a given status code. Note that we're using an interface{} type for the message parameter, rather than just a string type, as this gives us more flexibility over the values that we can include in the response.
func (*API) GetIpHandler ¶
func (api *API) GetIpHandler(w http.ResponseWriter, r *http.Request)
func (*API) GetIpInfoHandler ¶
func (api *API) GetIpInfoHandler(w http.ResponseWriter, r *http.Request)
func (*API) HealthcheckHandler ¶
func (api *API) HealthcheckHandler(w http.ResponseWriter, r *http.Request)
func (*API) MethodNotAllowedResponse ¶
func (api *API) MethodNotAllowedResponse(w http.ResponseWriter, r *http.Request)
The methodNotAllowedResponse() method will be used to send a 405 Method Not Allowed status code and JSON response to client
func (*API) NotFoundResponse ¶
func (api *API) NotFoundResponse(w http.ResponseWriter, r *http.Request)
The notFoundResponse() method will be used to send 404 Not Found status code and JSON response to the client.
func (*API) ServerErrorResponse ¶
The serverErrorResponse() method will be used when our application encounters an unexpected problem at runtime. It logs the detailed error message, then uses the errorResponse() helper to send a 500 Internal Server Error status code and JSON response (containing a generic error message) to the client.
func (*API) WriteJSON ¶
func (api *API) WriteJSON(w http.ResponseWriter, status int, data Envelope, headers http.Header) error
Define a WriteJSON helper for sending responses.
func (*API) WritePlainText ¶
func (api *API) WritePlainText(w http.ResponseWriter, status int, body string, headers http.Header) error
Define WritePlainText helper for sending responses.