Documentation ¶
Index ¶
- Constants
- func CheckForJSON(r *http.Request) error
- func GetHTTPErrorStatusCode(err error) int
- func MatchesContentType(contentType, expectedType string) bool
- func NewStatusError(code int) error
- func ParseForm(r *http.Request) error
- func UserFromContext(ctx context.Context) (user *userdb.BasicUser)
- func VersionFromContext(ctx context.Context) (ver string)
- func WriteError(w http.ResponseWriter, r *http.Request, err error)
- func WriteJSON(w http.ResponseWriter, code int, v interface{}) error
- type APIFunc
Constants ¶
const APIVersionKey key = 0
APIVersionKey is the client's requested API version.
const UserKey key = 1
UseKey is the key for userdb.User values in Contexts.
Variables ¶
This section is empty.
Functions ¶
func CheckForJSON ¶
CheckForJSON makes sure that the request's Content-Type is application/json.
func GetHTTPErrorStatusCode ¶
GetHTTPErrorStatusCode retrieve status code from error message
func MatchesContentType ¶
MatchesContentType validates the content type against the expected one
func NewStatusError ¶
NewStatusError returns a error object with HTTP status code.
func ParseForm ¶
ParseForm ensures the request form is parsed even with invalid content types. If we don't do this, POST method without Content-type (even with empty body) will fail.
func UserFromContext ¶
UserFromContext returns the authenticated user from the context using UserKey.
func VersionFromContext ¶
VersionFromContext returns an API version from the context using APIVersionKey.
func WriteError ¶
func WriteError(w http.ResponseWriter, r *http.Request, err error)
WriteError decodes a specific error and sends it in the response.