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.
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.