traefik_ratelimit

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

README

Local Mode

Traefik also offers a developer mode that can be used for temporary testing of plugins not hosted on GitHub. To use a plugin in local mode, the Traefik static configuration must define the module name (as is usual for Go packages) and a path to a Go workspace, which can be the local GOPATH or any directory.

The plugins must be placed in ./plugins-local directory, which should be in the working directory of the process running the Traefik binary. The source code of the plugin should be organized as follows:

 ├── docker-compose.yml
 └── plugins-local
    └── src
        └── github.com
            └── ghnexpress
                └── traefik-ratelimit
                    ├── main.go
                    ├── vendor
                    ├── go.mod
                    └── ...

# docker-compose.yml
version: "3.8"

services:

  traefik:
    image: traefik:v2.9
    container_name: traefik
    command:
      # - --log.level=DEBUG
      - --api
      - --api.dashboard
      - --api.insecure=true
      - --providers.docker=true
      - --entrypoints.web.address=:80
      - --experimental.localPlugins.plugindemo.moduleName=github.com/ghnexpress/traefik-ratelimit
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./plugins-local/src/github.com/ghnexpress/traefik-ratelimit:/plugins-local/src/github.com/ghnexpress/traefik-ratelimit
    labels:
      - traefik.http.middlewares.my-plugindemo.plugin.plugindemo.rate=1112
      - traefik.http.middlewares.my-plugindemo.plugin.plugindemo.redis.address=xxx
      - traefik.http.middlewares.my-plugindemo.plugin.plugindemo.redis.password=xxx

  whoami:
    image: traefik/whoami
    container_name: simple-service
    depends_on:
    - traefik
    labels:
      - traefik.enable=true
      - traefik.http.routers.whoami.rule=Host(`localhost`)
      - traefik.http.routers.whoami.entrypoints=web
      - traefik.http.routers.whoami.middlewares=my-plugindemo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New created a new plugin.

Types

type Config added in v1.0.0

type Config struct {
	Rate        int         `json:"rate,omitempty"`
	Redis       RedisConfig `json:"redis,omitempty"`
	RedisClient redis.Client
}

Config holds the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates and initializes the plugin configuration.

type RateLimit

type RateLimit struct {
	// contains filtered or unexported fields
}

func (*RateLimit) ServeHTTP

func (r *RateLimit) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type RedisConfig added in v1.0.0

type RedisConfig struct {
	Address  string `json:"address,omitempty"`
	Password string `json:"password,omitempty"`
}

Redis config.

Jump to

Keyboard shortcuts

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