http

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package http provides common structures and functions for HTTP controllers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodingError

func DecodingError(w http.ResponseWriter)

DecodingError writes DecodingError to response.

func ErrorJSON

func ErrorJSON(w http.ResponseWriter, error string, code int)

ErrorJSON writes error in JSON format and status code to response.

func HandleError

func HandleError(err error, fn func(e *usecase.Error))

HandleError calls fn or panics if error is internal.

func InternalServerError

func InternalServerError(w http.ResponseWriter)

InternalServerError writes InternalServerError to response.

func MethodNotAllowed

func MethodNotAllowed(w http.ResponseWriter, r *http.Request)

MethodNotAllowed writes MethodNotAllowed error to response.

func NotFound

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

NotFound writes NotFound error to response.

func UnsupportedMediaType

func UnsupportedMediaType(w http.ResponseWriter, r *http.Request, contentTypes []string)

UnsupportedMediaType writes UnsupportedMediaType error to response.

Types

type Middleware

type Middleware func(next http.Handler) http.Handler

Middleware is function that takes and returns http.Handler. It performs some function on request or response at specific stage in HTTP pipeline.

func ContentTypeMiddleware

func ContentTypeMiddleware(contentTypes ...string) Middleware

ContentTypeMiddleware creates a middleware verifying that Content-Type header has an allowed value. It returns Middleware instance.

func LoggerMiddleware

func LoggerMiddleware(logger log.Logger) Middleware

LoggerMiddleware creates a middleware that logs each request. It returns Middleware instance.

func RecovererMiddleware

func RecovererMiddleware(logger log.Logger) Middleware

RecovererMiddleware creates a middleware that handles panics and logs them. It returns Middleware instance.

Directories

Path Synopsis
Package v1 provides structures and functions to implement HTTP controllers.
Package v1 provides structures and functions to implement HTTP controllers.

Jump to

Keyboard shortcuts

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