Help us shape the future of Go! Take the 2026 Go Developer Survey

ipfilter

package module
v0.0.0-...-2034c2f Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2017 License: Apache-2.0 Imports: 3 Imported by: 2

README

IP Filter

Build Status

Tiny Golang lib for IP filtering.

This is helpful to restrict access to some endpoints on public service (e.g debug endpoints)

Well, why not just use proper auth (e.g basic, oidc, oauth2)?

Because some endpoints are problematic to hide using auth, like debug or metrics endpoints.

Usage

Filters are in a form of Bool conditions that takes IP in a form of net.IP

type Condition func(net.IP) bool

You can chain multiple conditions with some logic using ipfilter.OR(...) ipfilter.AND(...)

This package also contain useful HTTP middleware integration.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseIP

func ParseIP(address string) (ipAddr net.IP, err error)

ParseIP parses an IP (or hostport) string into net.IP.

func SingleIPNet

func SingleIPNet(ip net.IP) net.IPNet

SingleIPNet returns network that contains only specified IP.

Types

type Condition

type Condition func(net.IP) bool

Condition is just bool condition for whitelisting IP addresses.

func AND

func AND(conditions ...Condition) Condition

AND is an array of conditions with logic AND. If no condition is passed it returns false.

func IsPrivate

func IsPrivate() Condition

IsPrivate is condition that returns true only for IPs from a private network (VPN, localhost).

func IsWhitelisted

func IsWhitelisted(ips []net.IPNet) Condition

IsWhitelisted is an condition that returns true only for IPs from specified IP/network range.

func OR

func OR(conditions ...Condition) Condition

OR is an array of conditions with logic OR. If no condition is passed it returns false.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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