response

package
v0.0.0-...-76f5359 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderJson

func RenderJson(w http.ResponseWriter, res ApiResponse)

Types

type ApiResponse

type ApiResponse struct {
	Code     int               `json:"-"`
	Data     interface{}       `json:"data,omitempty"`
	Metadata Metadata          `json:"metadata,omitempty"`
	Headers  map[string]string `json:"-"`
	Errors   interface{}       `json:"errors,omitempty"`
}

func Accepted

func Accepted(data interface{}) ApiResponse

Accepted 202-Accepted with data in body

func BadRequest

func BadRequest(err error) ApiResponse

BadRequest 400-Bad Request

func ConvertServiceError

func ConvertServiceError(err error) ApiResponse

func CreateValidationErrResponse

func CreateValidationErrResponse(errMessages []validation.ValidationError) ApiResponse

func Created

func Created(data interface{}) ApiResponse

Created 201-Created with data in body

func ErrorResponse

func ErrorResponse(err error, status int) ApiResponse

ErrorResponse Custom error response

func InternalServerError

func InternalServerError(err error) ApiResponse

500 Internal server error

func Ok

func Ok(data interface{}) ApiResponse

Ok 200-OK with data in body

func PartialContent

func PartialContent(data interface{}) ApiResponse

PartialContent 206-Partial Content with data in body

func RecordNotFoundError

func RecordNotFoundError(err error, message string) ApiResponse

func ValidationError

func ValidationError(err error) ApiResponse

ValidationError 422-Unprocessable Enttity

func (ApiResponse) AddMetadata

func (a ApiResponse) AddMetadata(m Metadata) ApiResponse

type Error

type Error struct {
	Message    string                       `json:"message,omitempty"`
	Code       string                       `json:"code,omitempty"`
	StatusCode int                          `json:"status_code,omitempty"`
	Errors     []validation.ValidationError `json:"errors,omitempty"`
}

type Metadata

type Metadata struct {
	Total int `json:"total,omitempty"`
}

Jump to

Keyboard shortcuts

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