respond

package
v0.0.1-0...-104a2d1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

This package helps in forming common Response and Errors

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(opts ErrorOptions)

Respond with a translated error message

func Errors

func Errors(opts ErrorOptions)

Handle sending multiple error (mostly used for validation)

func IsValidationError

func IsValidationError(err error) (validation.ValidationErrors, bool)

IsValidationError checks if the error is a validation error

func Json

func Json(w http.ResponseWriter, statusCode int, data any, logger *zerolog.Logger)

JsonResponse responds with a success message and optional data

func Response

func Response(w http.ResponseWriter, r *http.Request, statusCode int, messageKey string, data any)

TranslatedResponse responds with a translated success message

func Status

func Status(w http.ResponseWriter, statusCode int)

Status responds with just a status code

Types

type ErrorOptions

type ErrorOptions struct {
	W          http.ResponseWriter
	R          *http.Request
	StatusCode int
	ClientErr  error
	ActualErr  error
	Logger     *zerolog.Logger
	Details    any
}

type ErrorResponse

type ErrorResponse struct {
	Status  string `json:"status"`
	Message string `json:"message"`
	Error   any    `json:"error,omitempty"`
}

type SuccessResponse

type SuccessResponse struct {
	Status  string `json:"status"`
	Message string `json:"message,omitempty"`
	Data    any    `json:"data,omitempty"`
}

Jump to

Keyboard shortcuts

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