Documentation ¶
Index ¶
- Variables
- func BadRequest(w http.ResponseWriter, reason interface{})
- func Forbidden(w http.ResponseWriter, reason interface{})
- func InProgress(w http.ResponseWriter, result interface{})
- func RenderListWithPages(w http.ResponseWriter, pageQuery db.PageQuery, total int64, list interface{})
- func ServerError(w http.ResponseWriter)
- func Success(w http.ResponseWriter, result interface{})
- func Unauthorized(w http.ResponseWriter, reason interface{})
- func WriteJSON(w http.ResponseWriter, status int, data interface{})
- type BaseRow
- type Page
- type R
Constants ¶
This section is empty.
Variables ¶
var ( // ResultServerError predefined response for `http.StatusInternalServerError`. ResultServerError = &R{ Code: http.StatusInternalServerError, Message: "Request Failed", } // ResultBadRequest predefined response for `http.StatusBadRequest`. ResultBadRequest = &R{ Code: http.StatusBadRequest, Message: "Bad Request", } // ResultSuccess predefined response for `http.StatusOK`. ResultSuccess = &R{ Code: http.StatusOK, Message: "Ok", } // ResultNotFound predefined response for `http.StatusNotFound`. ResultNotFound = &R{ Code: http.StatusNotFound, Message: "Not Found", } ResultUnauthorized = &R{ Code: http.StatusUnauthorized, Message: "Action Unauthorized", } // ResultForbidden predefined response for `http.StatusForbidden`. ResultForbidden = &R{ Code: http.StatusForbidden, Message: "Forbidden", } // ResultConflict predefined response for `http.StatusConflict`. ResultConflict = &R{ Code: http.StatusConflict, Message: "Already created", } )
nolint:gochecknoglobals
var PrettyMarshal bool // nolint:gochecknoglobals
PrettyMarshal is a flag that enable marshalling with indent.
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, reason interface{})
BadRequest renders `ResultBadRequest` with `reason` as an error.
func Forbidden ¶
func Forbidden(w http.ResponseWriter, reason interface{})
Forbidden renders `ResultForbidden` with `reason` as an error.
func InProgress ¶
func InProgress(w http.ResponseWriter, result interface{})
InProgress renders `ResultAccepted` with `reason` as an message.
func RenderListWithPages ¶
func RenderListWithPages(w http.ResponseWriter, pageQuery db.PageQuery, total int64, list interface{})
RenderListWithPages
func ServerError ¶
func ServerError(w http.ResponseWriter)
ServerError renders default http.StatusInternalServerError.
func Success ¶
func Success(w http.ResponseWriter, result interface{})
Success renders `result` as JSON with `http.StatusOK`.
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, reason interface{})
Unauthorized renders `ResultUnauthorized` with `reason` as an error.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, data interface{})
WriteJSON writes some response as WriteJSON to the `http.ResponseWriter`.
Types ¶
type BaseRow ¶
type BaseRow struct {
RowCount int64 `db:"row_count" json:"-"`
}
DEPRECATED BaseRow is a helper struct.
type Page ¶
type Page struct { // Page number of current page. Page uint64 `json:"page"` // PageSize is a number of records per page. PageSize uint64 `json:"pageSize"` // Order is ordering direction: asc or desc. Order string `json:"order"` // Total is total count of pages. Total int64 `json:"total"` // Total is total count of rows. TotalRows int64 `json:"total_rows"` // Records is an array of rows. Records interface{} `json:"records"` }
Page is a standard response structure to render paginated list.
func (*Page) Render ¶
func (page *Page) Render(w http.ResponseWriter)
Render writes page with http.StatusOK.
type R ¶
type R struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` Error interface{} `json:"errmsg,omitempty"` }
R is a structure for the http responses.
func (*R) Render ¶
func (r *R) Render(w http.ResponseWriter)
Render writes current response as WriteJSON to the `http.ResponseWriter`.