Documentation ¶
Index ¶
Constants ¶
const ( // DefaultPage is the default page number when none is // passed. DefaultPage = 1 // DefaultLimit is the default limit when none is // passed. DefaultLimit = 15 )
Variables ¶
var ( // DefaultParams represents the default params if // none were passed for the API. DefaultParams = params.Defaults{ Page: DefaultPage, Limit: DefaultLimit, OrderBy: "created_at", OrderDirection: "desc", } )
Functions ¶
func AbortJSON ¶
AbortJSON
Returns RespondJSON and aborts the request with given status, message and data.
func Respond ¶
func Respond(ctx *gin.Context, status int, message string, data interface{}, p ...*pagination.Pagination)
Respond
Returns RespondJSON and sends back the main data for use with the API. Returns status, message and data.
Types ¶
type ErrorJSON ¶
type ErrorJSON struct {
Errors validation.Errors `json:"errors"`
}
ErrorJSON defines the validation errors if there any when processing data via handlers.
type Meta ¶
type Meta struct { RequestTime string `json:"request_time"` ResponseTime string `json:"response_time"` LatencyTime string `json:"latency_time"` Pagination interface{} `json:"pagination,omitempty"` }
Meta defines any additional information for API request, including pagination for list routes.
func GetMeta ¶
func GetMeta(ctx *gin.Context, p []*pagination.Pagination) Meta
GetMeta
Processes the request and response time and calculates latency time. Sets pagination if the length is greater than one.
type RespondJSON ¶
type RespondJSON struct { Status int `json:"status"` Error bool `json:"error"` Message string `json:"message"` Meta Meta `json:"meta"` Data interface{} `json:"data"` }
RespondJSON defines the main struct for sending back data for API requests, it includes a status code, if the handler produced an error, a message, meta information and the main data.