middleware

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorOut

func ErrorOut(w http.ResponseWriter, code int, msg string)

ErrorOut outputs an error

Types

type AuthStatus

type AuthStatus int

AuthStatus is the status that is returned by an authenticator

const (
	AuthStatusPass    AuthStatus = iota // AuthStatusPass is returned when the authenticator cannot handle or doesn't care. Next authenticator is checked
	AuthStatusSuccess                   // AuthStatusSuccess allows the request, no other authenticators are checked
	AuthStatusFailure                   // AuthStatusFailure denies the request, no other authenticators are checked
)

AuthorizationContext is a context key that defines the authorization method

type Authenticate

type Authenticate struct {
	Chain []Authenticator
}

Authenticate holds multiple middleware/authenticators that can authenticate against the API

func (*Authenticate) Add

func (ma *Authenticate) Add(auth Authenticator)

Add a new authenticator to the list

func (*Authenticate) Middleware

func (ma *Authenticate) Middleware(next http.Handler) http.Handler

Middleware JWT token authentication

type Authenticator

type Authenticator interface {
	Authenticate(req *http.Request, route string) (AuthStatus, context.Context, error)
}

Authenticator allows you to use the struct in the multi-auth middleware

type ContextKeyType

type ContextKeyType int

ContextKeyType is the type used in context

const (
	AuthorizationContext ContextKeyType = iota // Defines which authorization type is used
	APIKeyContext                              // Used API key
	AuthKeyContext                             // Used Auth key
	ClaimsContext                              // Context key for fetching JWT claims
	AddressContext                             // Context key for fetching the address from the JWT
)

Context keys

type Logger

type Logger struct{}

Logger is a middleware that logs the timing of the given call

func (*Logger) Middleware

func (*Logger) Middleware(next http.Handler) http.Handler

Middleware Logs the request time

type PrettyJSON

type PrettyJSON struct {
	http.ResponseWriter
}

PrettyJSON is a middleware that will set a response header based on the request URI. This can be used to output json data either indented or not.

func (*PrettyJSON) Middleware

func (*PrettyJSON) Middleware(next http.Handler) http.Handler

Middleware sets header based on query param

type Tracer

type Tracer struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

Tracer is a middleware that logs the URL / status code of the call

func (*Tracer) Middleware

func (*Tracer) Middleware(next http.Handler) http.Handler

Middleware Prints request in log

func (*Tracer) WriteHeader

func (t *Tracer) WriteHeader(code int)

WriteHeader writes the given header to the response writer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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