Documentation
¶
Overview ¶
Package util provide utilities functions for web package.
Index ¶
- func DecodeJSONRequest(w http.ResponseWriter, r *http.Request, result interface{}) bool
- func HandleDbError(w http.ResponseWriter, err error)
- func ReadDBProjectID(w http.ResponseWriter, r *http.Request) (db.ProjectID, bool)
- func ReadDBVersionID(w http.ResponseWriter, r *http.Request) (db.VersionID, bool)
- func WriteJSONResponse(w http.ResponseWriter, httpStatus int, payload interface{}) bool
- func WriteJSONResponseWithHeaders(w http.ResponseWriter, httpStatus int, headers map[string]string, ...) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSONRequest ¶
func DecodeJSONRequest(w http.ResponseWriter, r *http.Request, result interface{}) bool
DecodeJSONRequest decode json payload from request to result. Write http.StatusBadRequest, if payload is not json or incorrect. Return true, if everything is ok.
func HandleDbError ¶
func HandleDbError(w http.ResponseWriter, err error)
HandleDbError write proper http status code based on database error.
func ReadDBProjectID ¶
ReadDBProjectID read db.ProjectID from request claims and routes path variables. It write http.StatusNotFound to w, if path variables are not valid. When everything goes well it return ok == true.
func ReadDBVersionID ¶
ReadDBVersionID read db.VersionID from request claims and routes path variables. It write http.StatusNotFound to w, if path variables are not valid. When everything goes well it return ok == true.
func WriteJSONResponse ¶
func WriteJSONResponse(w http.ResponseWriter, httpStatus int, payload interface{}) bool
WriteJSONResponse write payload to w with given httpStatus. Return true, if everything is ok.
func WriteJSONResponseWithHeaders ¶
func WriteJSONResponseWithHeaders(w http.ResponseWriter, httpStatus int, headers map[string]string, payload interface{}) bool
WriteJSONResponseWithHeaders works like WriteJSONResponse adding headers to HTTP Response headers. Return true, if everything is ok.
Types ¶
This section is empty.