middlewares

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package middlewares provides an interface for middlewares and the middlewares themselves.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthForward

type AuthForward struct {
	// The address of the authentication server.
	Address string `yaml:"address"`

	// The headers to forward from the request to the authentication server.
	// If this is nil, all headers will be forwarded.
	RequestHeaders []string `yaml:"requestHeaders"`

	// The headers to forward from the authentication server to the service.
	ResponseHeaders []string `yaml:"responseHeaders"`

	// Specifies whether to forward X-Forwarded-* headers to the authentication server.
	XForwarded bool `yaml:"xForwarded"`
}

AuthForward is a middleware that forwards the request to an authentication server and proxies to the service if the authentication is successful.

func (*AuthForward) Handle

func (a *AuthForward) Handle(next http.Handler) http.Handler

Handle communicates with the authentication server and proxies to the service if the authentication is successful.

type IPAllow

type IPAllow []string

IPAllow is a middleware that only allows requests from a list of IP addresses. Accepts IPs in CIDR notation.

func NewIPAllow

func NewIPAllow(allowedIPs []string) *IPAllow

NewIPAllow creates a new IPAllow middleware.

func (*IPAllow) Handle

func (ip *IPAllow) Handle(next http.Handler) http.Handler

Handle checks the remote address of the request and compares it to the allowed IP addresses. If the remote address is not in the allowed IP addresses, it returns a 403 Forbidden.

type Middleware

type Middleware interface {
	Handle(next http.Handler) http.Handler
}

Middleware is an interface for all middlewares.

type Middlewares

type Middlewares struct {
	IPAllow     *IPAllow     `yaml:"ipAllow"`
	AuthForward *AuthForward `yaml:"authForward"`
	XForward    *XForward    `yaml:"xForward"`
}

Middlewares is an exhaustive structure of all middlewares.

func (*Middlewares) List

func (c *Middlewares) List() []Middleware

List returns a list of middlewares that are not nil.

type XForward added in v0.0.2

type XForward struct {
	Enable bool `yaml:"enable"`
}

XForward is a middleware that adds X-Forwarded headers to the request.

func (*XForward) Handle added in v0.0.2

func (x *XForward) Handle(next http.Handler) http.Handler

Handle adds X-Forwarded headers to the request.

Jump to

Keyboard shortcuts

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