Giter VIP home page Giter VIP logo

traefik-plugin's Introduction

traefik-plugin

Traefik (Go) plugin samples. Enhance Traefik with your custom matcher & middleware (WIP)

Usage

  1. Create a dir where we dump traefik binary, our plugin (mymatcher.so) & sample config (traefik.toml)

    mkdir traefik-playground
    cd traefik-playground
    
  2. Build Traefik (based on v1.7.2) with go plugin support

    git clone -b goplugin-matcher https://github.com/tiket-libre/traefik $GOPATH/src/github.com/containous/traefik
    GOGC=off go build github.com/containous/traefik/cmd/traefik
    
  3. Build custom matcher plugin

    git clone https://github.com/tiket-libre/traefik-plugin $GOPATH/src/github.com/tiket-libre/traefik-plugin
    go build -buildmode=plugin -o mymatcher.so $GOPATH/src/github.com/tiket-libre/traefik-plugin/matcher/mymatcher.go
    
    # modify mymatcher.so path (plugin.matchers.mymatch.path) in sample-traefik-config.toml
    
  4. Run traefik (with sample config)

    # copy sample config to our playground dir
    cp $GOPATH/src/github.com/tiket-libre/traefik-plugin/traefik.toml .
    
    # (console #1) for the demo purpose, run a simple local http server as a Traefik backend
    python -m http.server
    
    # (console #2) run traefik
    ./traefik
    
  5. If we hit GET to http://localhost:7080/ (Traefik http entrypoint) with request body hello, http request will be forwarded to python backend.

Plugin Support

Matcher

A matcher plugin defines a struct that implements these two methods:

Load() interface{}
MatcherFunc (req *http.Request) bool

See this sample matcher plugin for a full example.

In a frontend rule, use our custom matcher by using Matcher keyword which refers to matcher var in the matcher plugin declaration.

[plugin]
    [plugin.matchers.mymatch]
    path = "./mymatcher.so"

# ...

[frontends]
  [frontends.frontend1]
  backend = "backend1"
    [frontends.frontend1.routes]
      [frontends.frontend1.routes.route0]
      rule = "Matcher: mymatch"

Caveats

  • Plugin hot reloading is not yet supported.

traefik-plugin's People

Contributors

fahrinh avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.