ipfilter

package module
v0.0.0-...-e7cd12c Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: MIT Imports: 6 Imported by: 1

README

gogin-ip-filter

IP filter middleware for Gin Web Framework

Usage
import (
    "github.com/gin-gonic/gin"
    "github.com/allape/gogin-ip-filter"
)

func main() {
    prefixes, hosts, err := ip_filter.ReadFile("allowed-ips.txt")
	if err != nil {
        panic(err)
    }
	
    r := gin.Default()
	r.Use(ip_filter.New(prefixes, hosts))
	
	// ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanPass

func CanPass(addr string, prefixes []netip.Prefix, hosts []string) (passed bool, prefix *netip.Prefix, host string, err error)

func New

func New(prefixes []netip.Prefix, hosts []string, onHandle OnHandle) func(ctx *gin.Context)

New middleware for Gin Web Framework

func ReadFile

func ReadFile(filename string) (prefixes []netip.Prefix, hosts []string, err error)

ReadFile reads the config file and sets up the IP filter. Line starts with # will be ignored It returns the prefixes and hosts that are allowed.

func SetupIPFilter

func SetupIPFilter(okIPSet []string) (prefixes []netip.Prefix, hosts []string)

Types

type OnHandle

type OnHandle func(ctx *gin.Context, passed bool, prefix *netip.Prefix, host string, err error)

Jump to

Keyboard shortcuts

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