common

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindAndValidate

func BindAndValidate[T any](c *fiber.Ctx) (*T, error)

BindAndValidate parses the request body and validates it using go-playground/validator. Returns a pointer to the struct (populated), or writes an error response and returns nil.

func ProblemDetailsJSON

func ProblemDetailsJSON(
	c *fiber.Ctx,
	title string,
	err error,
	detailOrStatus ...any,
) error

ProblemDetailsJSON writes a problem+json error response with a status code inferred from the error (if present). The title is set to the error message (if error), and detail can be a string, error, or structured object. Optionally, a status code can be provided as the last argument (int) to override the fallback status.

func SuccessResponseJSON

func SuccessResponseJSON(c *fiber.Ctx, status int, message string, data any) error

SuccessResponseJSON writes a JSON response with the given status, message, and data using the standard Response struct. Use for successful API responses (e.g., 200, 201, 202).

Types

type ProblemDetails

type ProblemDetails struct {
	Type     string `json:"type,omitempty"`     // A URI reference that identifies the problem type
	Title    string `json:"title"`              // Short, human-readable summary
	Status   int    `json:"status"`             // HTTP status code
	Detail   string `json:"detail,omitempty"`   // Human-readable explanation
	Instance string `json:"instance,omitempty"` // URI reference
	Errors   any    `json:"errors,omitempty"`   // Optional: additional error details
}

ProblemDetails follows RFC 9457 Problem Details for HTTP APIs.

type Response

type Response struct {
	Status  int    `json:"status"`         // HTTP status code
	Message string `json:"message"`        // Human-readable explanation
	Data    any    `json:"data,omitempty"` // Response data
}

Response defines the standard API response structure for success cases.

Jump to

Keyboard shortcuts

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