Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultResponder ¶
func SetDefaultResponder(responder Responder)
SetDefaultResponder sets default responder.
Types ¶
type Error ¶
type Error struct { // Code is a code of error Code int `json:"code" example:"400"` // Error is a string error representation Error string `json:"error" example:"Bad Request"` // Message is a message of error Message string `json:"message" example:"Validation error"` // Validation is a validation of error Validation map[string][]string `json:"validation,omitempty" example:"{'email': ['Email is required']}"` }
Error is a struct for error response
func (*Error) GetPayload ¶
func (e *Error) GetPayload() interface{}
GetPayload returns payload of response
type List ¶
type List struct { // Items is a list of items Items interface{} `json:"items" example:"[]"` // Total is a total count of items Total int `json:"total" example:"0"` // Pagination is a pagination of list Pagination *Pagination `json:"pagination,omitempty"` }
List represents a list of response data
func NewList ¶
func NewList(items interface{}, total int, pagination *Pagination) *List
NewList creates new list response
type Meta ¶
type Meta struct { // Title is a title of response Title string `json:"title" example:"Title"` // Description is a description of response Description string `json:"description" example:"Description"` // Version is a version of response Version string `json:"version" example:"1.0.0"` }
Meta represents a meta of response
type Pagination ¶
type Pagination struct { // Limit is a limit of items per page Limit int `json:"limit"` // Offset is a offset of items per page Offset int `json:"offset"` // Page is a current page Page int `json:"page"` // Pages is a total count of pages Pages int `json:"pages"` }
Pagination represents a pagination of list
func NewPagination ¶
func NewPagination(limit, offset, page, pages int) *Pagination
NewPagination creates new pagination
func NewPaginationFromInterface ¶
func NewPaginationFromInterface(source paginator) *Pagination
NewPaginationFromInterface creates new pagination from interface
type Responder ¶
type Responder interface { // JSON writes JSON response to http.ResponseWriter. // headersKV is a list of headers key-value pairs. // E.g. "Content-Type", "application/json", "X-Request-ID", "123" JSON(w http.ResponseWriter, response Responser, headersKV ...string) error }
Responder is an interface for response. Respond writes response to http.ResponseWriter.
func NewDefaultResponder ¶
func NewDefaultResponder() Responder
NewDefaultResponder creates new default responder.
type Response ¶
type Response struct { // Code is a code of response Code int `json:"code" example:"200"` // Message is a message of response Message string `json:"message" example:"OK"` // Data is a data of response Data interface{} `json:"data" example:"{}"` // Meta is a meta of response Meta *Meta `json:"meta,omitempty"` }
Response is a struct for response
func NewCreated ¶
NewCreated creates new created response
func (*Response) GetPayload ¶
func (r *Response) GetPayload() interface{}
GetPayload returns payload of response
Click to show internal directories.
Click to hide internal directories.