traefik_geoip2

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: MIT Imports: 4 Imported by: 0

README

MaxMind GeoIP2 Plugin for Traefik

This plugin is Traefik middleware that looks up IP information(Country, City, ASN) from the MaxMind GeoIP DB.

This plugin is built using the Go GeoIP2 reader.

Usage

For a plugin to be active for a given Traefik instance, it must be declared in the static configuration.

Configuration

For each plugin, the Traefik static configuration must define the module name (as is usual for Go packages)

The following declaration (given here in YAML) defines a plugin:

# Static configuration

experimental:
  plugins:
    geoip2:
      moduleName: github.com/scorpion1201/traefik-geoip2
      version: 0.1.0

Here is an example of a file provider dynamic configuration (given here in YAML), where the interesting part is the http.middlewares section:

# Dynamic configuration
http:
  routers:
    my-router:
      rule: host(`foobar.localhost`)
      service: service-foo
      entryPoints:
        - web
      middlewares:
        - geoip2-plugin
  services:
    service-foo:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:5000
  middlewares:
    geoip2-plugin:
      plugin:
        geoip2:
          ASNFileName: /path/to/GeoIP2-ASN.mmdb
          CityFileName: /path/to/GeoIP2-City.mmdb
          CountryFileName: /path/to/GeoIP2-Country.mmdb

Contributing

Contributions welcome! Please fork the repository and open a pull request with your changes.

License

This is free software, licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

Types

type Config

type Config struct {
	ASNFileName     string `json:"asnFileName,omitempty"`
	CityFileName    string `json:"cityFileName,omitempty"`
	CountryFileName string `json:"countryFileName,omitempty"`
}

func CreateConfig

func CreateConfig() *Config

type GeoIP2

type GeoIP2 struct {
	AsnDB     *geoip2.Reader
	CityDB    *geoip2.Reader
	CountryDB *geoip2.Reader
	// contains filtered or unexported fields
}

func (*GeoIP2) ServeHTTP

func (g *GeoIP2) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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