presenter

package
v0.0.0-...-a1c72dd Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package presenter formats output representation for the external world (JSON payload shape, view models). Keeps controllers thin.

Package presenter formats output representation for the external world (JSON payload shape, view models). Keeps controllers thin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BookPresenter

type BookPresenter struct {
	// contains filtered or unexported fields
}

BookPresenter prepares a domain.Book to be returned to an http interface.

func NewBookPresenter

func NewBookPresenter(logger *slog.Logger) *BookPresenter

NewBookPresenter creates a new instance of BookPresenter.

func (*BookPresenter) Present

func (p *BookPresenter) Present(book *domain.Book) map[string]any

Present returns the map representation of a domain.Book. Present prefixes the book ID with the resource type (book:) and transform the title to Title Case based on the book language.

type ErrorPresenter

type ErrorPresenter struct {
	// contains filtered or unexported fields
}

ErrorPresenter prepares an error to be returned to an http interface.

func NewErrorPresenter

func NewErrorPresenter(logger *slog.Logger) *ErrorPresenter

NewErrorPresenter creates a new instance of ErrorPresenter.

func (*ErrorPresenter) Present

func (p *ErrorPresenter) Present(w http.ResponseWriter, err error, code int)

Present writes the JSON representation of the error directly to w. Additionally, it writes the correct error code to w. Internal errors are caught and replaced with a default message. If the error is one of the known types, the code is overwritten with the correct one.

Jump to

Keyboard shortcuts

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