middleware

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package middleware provides HTTP middleware for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuthentication

func BasicAuthentication(allowed []string) func(next http.Handler) http.Handler

BasicAuthentication is a middleware that authenticates via basic auth, if enabled allowed is a list of user:bcrypt(passwd) strings generated by `htpasswd -nbB user passwd`

func ContentTypeJSON

func ContentTypeJSON(next http.Handler) http.Handler

ContentTypeJSON sets Content-Type (HTTP header) to `application/json`.

func DevCORS

func DevCORS(next http.Handler) http.Handler

DevCORS allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served.

func NewStructuredLogger

func NewStructuredLogger(logger *logrus.Logger) func(next http.Handler) http.Handler

NewStructuredLogger creates a middleware with logrus logger.

func ServeFile

func ServeFile(filename string) http.HandlerFunc

ServeFile handles requests for a specific file..

func SinglePageApplication

func SinglePageApplication(indexHTML, title, header string) http.HandlerFunc

SinglePageApplication renders and serves the index.html.

Types

type StructuredLogger

type StructuredLogger struct {
	Logger *logrus.Logger
}

StructuredLogger is a simple, but powerful implementation of a custom structured logger backed on logrus. I encourage users to copy it, adapt it and make it their own. Also take a look at https://github.com/go-chi/httplog for a dedicated pkg based on this work, designed for context-based http routers.

func (*StructuredLogger) NewLogEntry

func (l *StructuredLogger) NewLogEntry(r *http.Request) middleware.LogEntry

NewLogEntry creates a new LogEntry for the request.

Jump to

Keyboard shortcuts

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