Documentation ¶
Index ¶
- func Error(w http.ResponseWriter, err string, code int)
- func NoContent(w http.ResponseWriter)
- func TestEmptyResponse(t *testing.T, w *httptest.ResponseRecorder)
- func TestErrorExpectedResponse(t *testing.T, router *mux.Router, operation, url, msg string, code int, ...)
- func TestGetErrorExpectedResponse(t *testing.T, router *mux.Router, url, msg string, code int)
- func TestHandlerFailsWithoutAuthenticatedUser(t *testing.T, handler func(w http.ResponseWriter, r *http.Request))
- func TestListBadRequests(t *testing.T, entity string, router *mux.Router)
- func TestListFailsBadPage(t *testing.T, entity string, router *mux.Router, code int)
- func TestListFailsPageTooBig(t *testing.T, entity string, router *mux.Router, code int)
- func TestListValidResponse(t *testing.T, router *mux.Router, entity string, items []interface{}, ...)
- func TestListValidResponseWithParams(t *testing.T, router *mux.Router, entity string, items []interface{}, ...)
- func TestPostErrorExpectedResponse(t *testing.T, router *mux.Router, url, msg string, code int, data io.Reader)
- func TestPutErrorExpectedResponse(t *testing.T, router *mux.Router, url, msg string, code int, data io.Reader)
- func TestResponseBody(t *testing.T, w *httptest.ResponseRecorder, expected string)
- func TestResponseForError(t *testing.T, w *httptest.ResponseRecorder, msg string, code int)
- func TestResponseObject(t *testing.T, w *httptest.ResponseRecorder, expected interface{}, code int)
- func UnauthorizedError(w http.ResponseWriter, err string)
- func WriteJSON(w http.ResponseWriter, v interface{}, code int)
- type ListResponse
- type Logger
- type LookupStringIDResponse
- type LookupUintIDResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Error ¶
func Error(w http.ResponseWriter, err string, code int)
Error produces a JSON error response with the following structure: {"error":"some error message"}
func TestEmptyResponse ¶
func TestEmptyResponse(t *testing.T, w *httptest.ResponseRecorder)
TestEmptyResponse tests an empty 204 response
func TestErrorExpectedResponse ¶
func TestErrorExpectedResponse(t *testing.T, router *mux.Router, operation, url, msg string, code int, data io.Reader)
TestErrorExpectedResponse is the generic test code for testing for a bad response
func TestGetErrorExpectedResponse ¶
TestGetErrorExpectedResponse ...
func TestHandlerFailsWithoutAuthenticatedUser ¶
func TestHandlerFailsWithoutAuthenticatedUser(t *testing.T, handler func(w http.ResponseWriter, r *http.Request))
TestHandlerFailsWithoutAuthenticatedUser ...
func TestListBadRequests ¶
TestListBadRequests tests a list response for common bad request failures
func TestListFailsBadPage ¶
TestListFailsBadPage tests a list endpoint for a bad page response
func TestListFailsPageTooBig ¶
TestListFailsPageTooBig a list endpoint for a too big page response
func TestListValidResponse ¶
func TestListValidResponse(t *testing.T, router *mux.Router, entity string, items []interface{}, assertExpectations func())
TestListValidResponse ...
func TestListValidResponseWithParams ¶
func TestListValidResponseWithParams(t *testing.T, router *mux.Router, entity string, items []interface{}, assertExpectations func(), params map[string]string)
TestListValidResponseWithParams tests a list endpoint for a valid response with default settings
func TestPostErrorExpectedResponse ¶
func TestPostErrorExpectedResponse(t *testing.T, router *mux.Router, url, msg string, code int, data io.Reader)
TestPostErrorExpectedResponse ...
func TestPutErrorExpectedResponse ¶
func TestPutErrorExpectedResponse(t *testing.T, router *mux.Router, url, msg string, code int, data io.Reader)
TestPutErrorExpectedResponse ...
func TestResponseBody ¶
func TestResponseBody(t *testing.T, w *httptest.ResponseRecorder, expected string)
TestResponseBody tests response body is equal to expected string
func TestResponseForError ¶
TestResponseForError tests a response w to see if it returned an error msg with http code
func TestResponseObject ¶
func TestResponseObject(t *testing.T, w *httptest.ResponseRecorder, expected interface{}, code int)
TestResponseObject tests response body is equal to expected object in JSON form
func UnauthorizedError ¶
func UnauthorizedError(w http.ResponseWriter, err string)
UnauthorizedError has to contain WWW-Authenticate header See http://self-issued.info/docs/draft-ietf-oauth-v2-bearer.html#rfc.section.3
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, v interface{}, code int)
WriteJSON writes JSON response
Types ¶
type ListResponse ¶
ListResponse ...
func NewListResponse ¶
func NewListResponse(count, page int, self, first, last, previous, next, embedName string, items interface{}) *ListResponse
NewListResponse creates new ListResponse instance
type Logger ¶
type Logger struct { // Logger inherits from log.Logger used to log messages with the Logger middleware *log.Logger }
Logger is a middleware handler that logs the request as it goes in and the response as it goes out.
func (*Logger) ServeHTTP ¶
func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)