util

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2018 License: GPL-3.0, GPL-3.0-or-later Imports: 6 Imported by: 7

Documentation

Overview

Package util provide utilities functions for web package.

Index

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

func ReadDBProjectID(w http.ResponseWriter, r *http.Request) (db.ProjectID, bool)

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

func ReadDBVersionID(w http.ResponseWriter, r *http.Request) (db.VersionID, bool)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL