middleware

package
v0.0.0-...-93fcf36 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Disable authentication entirely, allowing all requests
	NoAuth = false
)

Functions

func Auth

Auth checks the token in the Authorization header against the provided database. The token is then provided in the context value If `NoAuth` is false - all checks are skipped and the dummy token is set in the context

func Error

func Error(handler ErrorHandler) http.HandlerFunc

Error wraps the custom handler, which is an extension of http.HandlerFunc, that can return an error. When the error is not nil, Error encodes it into a standard json form, as follows:

{ "error": true, "message": "..." }

func Json

func Json(next http.HandlerFunc) http.HandlerFunc

Json sets the "Content-Type" header of the response to "application/json; charset=utf-8"

Types

type ErrorHandler

type ErrorHandler func(http.ResponseWriter, *http.Request) error

ErrorHandler is similar to http.HandlerFunc, but it can also return an error

type ServerError

type ServerError struct {
	Error   bool   `json:"error"`
	Message string `json:"message"`
}

Jump to

Keyboard shortcuts

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