util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ValidationErrorCode int = 400
)

Variables

This section is empty.

Functions

func NewData

func NewData(ctx *gin.Context, status int, data interface{})

NewData returns a new response following the DataResponse schema

func NewError

func NewError(ctx *gin.Context, status int, err error)

NewError returns a new error response

func NewResponse

func NewResponse(ctx *gin.Context, status int, obj interface{})

NewResponse returns a new response

func NewValidationError

func NewValidationError(ctx *gin.Context, err error)

NewValidationError returns a new validation error response

func ValidateBody

func ValidateBody(ctx *gin.Context, obj interface{}) error

func ValidateUUID

func ValidateUUID(id string) (uuid.UUID, error)

Types

type DataResponse

type DataResponse struct {
	Code int         `json:"code" example:"200"`
	Data interface{} `json:"data,omitempty"`
}

DataResponse example

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code" example:"400"`
	Message string `json:"message" example:"status bad request"`
}

ErrorResponse represents an error API response

type ValidationErrorResponse

type ValidationErrorResponse struct {
	Code    int               `json:"code" example:"400"`
	Message string            `json:"message" example:"status bad request"`
	Fields  map[string]string `json:"fields"`
}

ValidationErrorResponse represents a validation error API response

Jump to

Keyboard shortcuts

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