middleware

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package middleware contains middlewares for logging, auth, custom errors and so on.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(
	realm string,
	authHeader string,
	credentialsFile string,
) func(next http.Handler) http.Handler

Auth middleware which uses Firebase auth tokens and puts userID into ctx for handlers to decide what can be accessed by given user

func Base

func Base(
	logger *log.Logger,
	requestIDheader string,
) func(next http.Handler) http.Handler

Base middleware which - loggs information about request and response - catches panic and logs out the debug.Stack - prepares requestID (from specified header or generates new one)

func Error

func Error(
	contentType string,
	responses map[int][]byte,
) func(next http.Handler) http.Handler

Error allows overriding net/http error responses with your own..

You might want to use one for rest api with text/plain content and otherone for stuff vidible by user with text/html content type.

Here is an example usage:

contentType := "text/plain; charset=utf-8"
customErrors := make(map[int][]byte)
customErrors[http.StatusNotFound] = []byte("custom 404..")
...

errorMiddleware := middleware.Error(contentType, customErrors)
server := &http.Server{
	Addr: ":XXXX",
	Handler: errorMiddleware(router),
}
server.ListenAndServe()

Types

This section is empty.

Jump to

Keyboard shortcuts

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