helpers

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPage = 1
	DefaultSize = 20
	MaxSize     = 200
)

Variables

View Source
var ErrInvalidPage = errors.New("invalid page parameter")
View Source
var ErrInvalidSize = errors.New("invalid size parameter")
View Source
var ErrInvalidUUIDParam = errors.New("invalid uuid path parameter")

Functions

func ParseConsumerAssociationID

func ParseConsumerAssociationID[K ids.Kind](c *fiber.Ctx, targetParam string) (ids.GatewayID, ids.ConsumerID, ids.ID[K], error)

func ParseGatewayID

func ParseGatewayID(c *fiber.Ctx) (ids.GatewayID, error)

ParseGatewayID parses the required :gateway_id path param shared by every gateway-scoped collection handler (create/list).

func ParseGatewayScopedID

func ParseGatewayScopedID[K ids.Kind](c *fiber.Ctx) (ids.GatewayID, ids.ID[K], error)

ParseGatewayScopedID parses the required :gateway_id and :id path params shared by every gateway-scoped sub-resource handler (get/update/delete).

func ParsePage

func ParsePage(c *fiber.Ctx) (int, error)

func ParseSize

func ParseSize(c *fiber.Ctx) (int, error)

func ParseUUIDParam

func ParseUUIDParam[K ids.Kind](c *fiber.Ctx, name string) (ids.ID[K], error)

func WriteCreated

func WriteCreated(c *fiber.Ctx, body any) error

func WriteError

func WriteError(c *fiber.Ctx, err error) error

WriteError is a convenience wrapper around MapDomainError + JSON write. Every error funnelled through here is logged at Error level with the caller site and a stack trace, so a failing endpoint always leaves a trace even when the wire response collapses to a generic code (e.g. 500 "internal_error").

func WriteListEnvelope

func WriteListEnvelope(c *fiber.Ctx, items any, page, size, total int) error

func WriteNoContent

func WriteNoContent(c *fiber.Ctx) error

func WriteOK

func WriteOK(c *fiber.Ctx, body any) error

Types

type ErrorBody

type ErrorBody struct {
	Error   string `json:"error"`
	Message string `json:"message,omitempty"`
}

ErrorBody is the JSON shape emitted on every error response. Handlers MUST go through MapDomainError so the wire format stays consistent.

func MapDomainError

func MapDomainError(err error) (int, ErrorBody)

MapDomainError translates an application/domain error into the matching HTTP status code and a stable error code string. Entity-specific sentinels add their cases here as their `<entity>-a` slices land.

Unknown errors collapse to 500 + "internal_error" — callers should have already logged the underlying error with the request context.

type ListEnvelope

type ListEnvelope struct {
	Items any `json:"items"`
	Page  int `json:"page"`
	Size  int `json:"size"`
	Total int `json:"total"`
}

Jump to

Keyboard shortcuts

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