middleware

package
v0.0.0-...-8bff5d1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cors

func Cors(next http.Handler) http.Handler

Cors sets origin, credentials, headers and methods allowed.

func GZIPCompress

func GZIPCompress(next http.Handler) http.Handler

GZIPCompress checks if the request accepts encoding and utilized gzip or proceed without compressing.

func LogFormatter

func LogFormatter(next http.Handler) http.Handler

LogFormatter prints the server requests on the console.

func Recover

func Recover(next http.Handler) http.Handler

Recover recovers any panic (from libraries) and handles the error to prevent the server from shutting down.

func Secure

func Secure(next http.Handler) http.Handler

Secure adds security headers to the http connection.

Types

type Auth

type Auth struct {
	DB          *sqlx.DB
	UserService user.Service
	Session     auth.Session
}

Auth contains the elements needed to authorize users.

func (*Auth) AdminsOnly

func (a *Auth) AdminsOnly(next http.Handler) http.Handler

AdminsOnly requires the user to be an administrator to proceed.

func (*Auth) RequireLogin

func (a *Auth) RequireLogin(next http.Handler) http.Handler

RequireLogin makes sure the user is logged in before forwarding the request, it returns an error otherwise.

type GZIPReponseWriter

type GZIPReponseWriter struct {
	// contains filtered or unexported fields
}

GZIPReponseWriter is a response writer containing a GZIP writer in it

func NewGZIPResponseWriter

func NewGZIPResponseWriter(rw http.ResponseWriter) *GZIPReponseWriter

NewGZIPResponseWriter returns a new GZIPResponseWriter.

func (*GZIPReponseWriter) Flush

func (g *GZIPReponseWriter) Flush()

Flush flushes any pending compressed data and closes the gzip writer.

func (*GZIPReponseWriter) Header

func (g *GZIPReponseWriter) Header() http.Header

Header is implemented to satisfy the response writer interface.

func (*GZIPReponseWriter) Write

func (g *GZIPReponseWriter) Write(d []byte) (int, error)

Write is implemented to satisfy the response writer interface.

func (*GZIPReponseWriter) WriteHeader

func (g *GZIPReponseWriter) WriteHeader(statuscode int)

WriteHeader is implemented to satisfy the response writer interface.

type MetricsHandler

type MetricsHandler struct {
	// contains filtered or unexported fields
}

MetricsHandler implements a scrapper middleware.

func NewMetrics

func NewMetrics() MetricsHandler

NewMetrics initializes the metrics and returns the handler used to scrap.

func (MetricsHandler) Scrap

func (m MetricsHandler) Scrap(next http.Handler) http.Handler

Scrap registers endpoint behavior metrics.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter uses a leaky bucket algorithm for limiting the requests to the API from the same host.

func NewRateLimiter

func NewRateLimiter(config config.RateLimiter, rdb *redis.Client) *RateLimiter

NewRateLimiter returns a rate limiter with the configuration values passed.

func (*RateLimiter) Limit

func (rl *RateLimiter) Limit(next http.Handler) http.Handler

Limit make sure no one abuses the API by using token bucket algorithm.

Jump to

Keyboard shortcuts

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