error

package
v0.0.0-...-18c2177 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProblemDetails

type ProblemDetails struct {
	Type        string                     `json:"type,omitempty" example:"urn:auth-session-api/healthcheck/check"`
	Title       string                     `json:"title,omitempty" example:"Health check server failed"`
	Status      int                        `json:"status,omitempty" example:"500"`
	Detail      string                     `json:"detail,omitempty" example:"An error occurred while performing the health check"`
	Instance    string                     `json:"instance,omitempty" example:"/health"`
	FieldErrors []ProblemDetailsFieldError `json:"errors,omitempty"`
	Limit       int                        `json:"limit,omitempty" example:"10"`
	Code        int                        `json:"code,omitempty" example:"1001"`
}

ProblemDetails represents an RFC 7807 problem details response

func NewProblemDetails

func NewProblemDetails() ProblemDetails

NewProblemDetails creates a new ProblemDetails with default type "about:blank".

func (ProblemDetails) AddFieldError

AddFieldError appends a single field error to the ProblemDetails.

func (ProblemDetails) AddFieldErrors

func (p ProblemDetails) AddFieldErrors(errs []ProblemDetailsFieldError) ProblemDetails

AddFieldErrors appends multiple field errors to the ProblemDetails.

func (ProblemDetails) Error

func (p ProblemDetails) Error() string

func (ProblemDetails) ServeJSON

func (p ProblemDetails) ServeJSON(w http.ResponseWriter, _ *http.Request) error

ServeJSON writes the ProblemDetails as JSON to the HTTP response writer.

func (ProblemDetails) WithCode

func (p ProblemDetails) WithCode(code int) ProblemDetails

WithCode sets the code field of the ProblemDetails.

func (ProblemDetails) WithDetail

func (p ProblemDetails) WithDetail(detail string) ProblemDetails

WithDetail sets the detail field of the ProblemDetails.

func (ProblemDetails) WithInstance

func (p ProblemDetails) WithInstance(instance string) ProblemDetails

WithInstance sets the instance field of the ProblemDetails.

func (ProblemDetails) WithLimit

func (p ProblemDetails) WithLimit(limit int) ProblemDetails

WithLimit sets the limit field of the ProblemDetails.

func (ProblemDetails) WithStatus

func (p ProblemDetails) WithStatus(status int) ProblemDetails

WithStatus sets the HTTP status code of the ProblemDetails.

func (ProblemDetails) WithTitle

func (p ProblemDetails) WithTitle(title string) ProblemDetails

WithTitle sets the title field of the ProblemDetails.

func (ProblemDetails) WithType

func (p ProblemDetails) WithType(typeContext, t string) ProblemDetails

WithType sets the type field using a formatted URN pattern.

type ProblemDetailsFieldError

type ProblemDetailsFieldError struct {
	Field   string `json:"field" example:"username"`
	Message string `json:"message" example:"validation failed for 'required' tag"`
}

ProblemDetailsFieldError represents a field validation error

func NewProblemDetailsFieldError

func NewProblemDetailsFieldError(field, message string) ProblemDetailsFieldError

NewProblemDetailsFieldError creates a new ProblemDetailsFieldError with the specified field and message.

func NewProblemDetailsFromStructValidation

func NewProblemDetailsFromStructValidation(ve validator.ValidationErrors) []ProblemDetailsFieldError

NewProblemDetailsFromStructValidation converts validator.ValidationErrors to ProblemDetailsFieldError slice.

Jump to

Keyboard shortcuts

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