utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record not found")
	ErrEditConflict   = errors.New("edit conflict")
	ErrDuplicateEmail = errors.New("duplicate email")
)

Functions

func AuthenticationRequiredResponse added in v0.2.1

func AuthenticationRequiredResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func BadRequestResponse added in v0.2.1

func BadRequestResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, err error)

func EditConflictResponse added in v0.2.1

func EditConflictResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func ErrorResponse added in v0.2.1

func ErrorResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, status int, message any)

func FailedValidationResponse added in v0.2.1

func FailedValidationResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, errors map[string]string)

func InvalidAuthenticationTokenResponse added in v0.2.1

func InvalidAuthenticationTokenResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func InvalidCredentialsResponse added in v0.2.1

func InvalidCredentialsResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func LogError added in v0.2.1

func LogError(r *http.Request, logger *slog.Logger, err error)

func MethodNotAllowedResponse added in v0.2.1

func MethodNotAllowedResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func NotFoundResponse added in v0.2.1

func NotFoundResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func RateLimitExceededResponse added in v0.2.1

func RateLimitExceededResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger)

func ReadIDParam added in v0.2.1

func ReadIDParam(r *http.Request) (int64, error)

Retrieve the "id" URL parameter from the current request context, then convert it to an integer and return it. If the operation isn't successful, return 0 and an error.

func ReadJSON added in v0.2.1

func ReadJSON(w http.ResponseWriter, r *http.Request, dst any) error

func ServerErrorResponse added in v0.2.1

func ServerErrorResponse(w http.ResponseWriter, r *http.Request, logger *slog.Logger, err error)

func WriteJSON added in v0.2.1

func WriteJSON(w http.ResponseWriter, status int, data Envelope, headers http.Header) error

Define a writeJSON() helper for sending responses. This takes the destination http.ResponseWriter, the HTTP status code to send, the data to encode to JSON, and a header map containing any additional HTTP headers we want to include in the response.

Types

type Envelope added in v0.2.1

type Envelope map[string]any

Jump to

Keyboard shortcuts

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