ipfilter

package module
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 6 Imported by: 0

README

Test workflow Go Report Codecov
Become a sponsor Donate Paypal

About

Middleware that provides ipfilter support for echo framework backed by jpillora/ipfilter.

Installation

go get github.com/crazy-max/echo-ipfilter

Example

package main

import (
	"net/http"

	ipfilter "github.com/crazy-max/echo-ipfilter"
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
)

func main() {
	e := echo.New()

	e.Use(ipfilter.MiddlewareWithConfig(ipfilter.Config{
		Skipper: middleware.DefaultSkipper,
		WhiteList: []string{
			"10.1.1.0/24",
			"10.1.2.0/24",
		},
		BlockByDefault: true,
	}))

	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!\n")
	})

	e.Logger.Fatal(e.Start(":1323"))
}

Contributing

Want to contribute? Awesome! The most basic way to show your support is to star the project, or to raise issues. You can also support this project by becoming a sponsor on GitHub or by making a Paypal donation to ensure this journey continues indefinitely!

Thanks again for your support, it is much appreciated! 🙏

License

MIT. See LICENSE for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	Skipper:        middleware.DefaultSkipper,
	BlockByDefault: false,
}

DefaultConfig is the default IPFilter middleware config

Functions

func Middleware

func Middleware() echo.MiddlewareFunc

Middleware returns an IPFilter middleware to filter requests by ip matching / blocking.

func MiddlewareWithConfig

func MiddlewareWithConfig(config Config) echo.MiddlewareFunc

MiddlewareWithConfig returns an IPFilter middleware with config. See: `IPFilter()`.

Types

type Config

type Config struct {
	// Skipper defines a function to skip middleware.
	// default middleware.DefaultSkipper
	Skipper middleware.Skipper

	// WhiteList is an allowed ip list.
	WhiteList []string

	// BlackList is a disallowed ip list.
	BlackList []string

	// Block by default.
	BlockByDefault bool

	// called with the newly created filter object to allow for
	// controlling the filter during runtime.
	// The underlying filter implementation is thankfully threadsafe
	CreatedFilter func(*ipfilter.IPFilter)
}

Config defines the config for IPFilter middleware.

Jump to

Keyboard shortcuts

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