reject

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

This package provides helper functions to reject the incoming request. In order to facilitate of the usage of this package, it is required to create a new instance of the LoggerSupport struct and provide an instance of slog.Logger. The response format is JSON and the error message is provided in the "error" field. Example: { "error": "Not Found" }

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoggerSupport

type LoggerSupport struct {
	Logger         *slog.Logger // Logger instance
	RequestEnabled bool         // Enable request logging
}

NewLoggerSupport creates a new instance of the LoggerSupport struct.

func (*LoggerSupport) BadRequest

func (app *LoggerSupport) BadRequest(w http.ResponseWriter, r *http.Request)

Rejects the request with HTTP status code 400 Bad Request and a JSON response body.

func (*LoggerSupport) Forbidden

func (app *LoggerSupport) Forbidden(w http.ResponseWriter, r *http.Request)

Rejects the request with HTTP status code 403 Forbidden and a JSON response body.

func (*LoggerSupport) InternalServerError

func (app *LoggerSupport) InternalServerError(w http.ResponseWriter, r *http.Request)

Rejects the request with HTTP status code 500 Internal Server Error and a JSON response body.

func (*LoggerSupport) NotFound

func (app *LoggerSupport) NotFound(w http.ResponseWriter, r *http.Request)

Rejects the request with HTTP status code 404 Not Found and a JSON response body.

func (*LoggerSupport) Unauthorized

func (app *LoggerSupport) Unauthorized(w http.ResponseWriter, r *http.Request)

Rejects the request with HTTP status code 401 Unauthorized and a JSON response body.

func (*LoggerSupport) ValidationError added in v0.0.3

func (app *LoggerSupport) ValidationError(w http.ResponseWriter, r *http.Request, errorMessages map[string]string)

Rejects the request with HTTP status code 400 Bad Request and a JSON response body containing a validation error message.

Jump to

Keyboard shortcuts

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