{"id":13564864,"url":"https://github.com/traefik/plugindemo","last_synced_at":"2025-08-24T17:16:05.298Z","repository":{"id":47527549,"uuid":"279099405","full_name":"traefik/plugindemo","owner":"traefik","description":"This repository includes an example plugin, for you to use as a reference for developing your own plugins","archived":false,"fork":false,"pushed_at":"2022-11-23T17:23:41.000Z","size":52,"stargazers_count":140,"open_issues_count":5,"forks_count":45,"subscribers_count":19,"default_branch":"master","last_synced_at":"2024-12-11T13:52:05.687Z","etag":null,"topics":["traefik","traefik-plugin"],"latest_commit_sha":null,"homepage":"https://plugins.traefik.io/plugins/628c9ee2108ecc83915d7764/demo-plugin","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/traefik.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-12T16:04:10.000Z","updated_at":"2024-10-27T21:41:41.000Z","dependencies_parsed_at":"2023-01-22T08:30:13.888Z","dependency_job_id":null,"html_url":"https://github.com/traefik/plugindemo","commit_stats":null,"previous_names":["containous/plugindemo"],"tags_count":4,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fplugindemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fplugindemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fplugindemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traefik%2Fplugindemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/traefik","download_url":"https://codeload.github.com/traefik/plugindemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230445927,"owners_count":18227060,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["traefik","traefik-plugin"],"created_at":"2024-08-01T13:01:37.220Z","updated_at":"2024-12-19T14:08:06.069Z","avatar_url":"https://github.com/traefik.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"This repository includes an example plugin, `demo`, for you to use as a reference for developing your own plugins.\n\n[![Build Status](https://github.com/traefik/plugindemo/workflows/Main/badge.svg?branch=master)](https://github.com/traefik/plugindemo/actions)\n\nThe existing plugins can be browsed into the [Plugin Catalog](https://plugins.traefik.io).\n\n# Developing a Traefik plugin\n\n[Traefik](https://traefik.io) plugins are developed using the [Go language](https://golang.org).\n\nA [Traefik](https://traefik.io) middleware plugin is just a [Go package](https://golang.org/ref/spec#Packages) that provides an `http.Handler` to perform specific processing of requests and responses.\n\nRather than being pre-compiled and linked, however, plugins are executed on the fly by [Yaegi](https://github.com/traefik/yaegi), an embedded Go interpreter.\n\n## Usage\n\nFor a plugin to be active for a given Traefik instance, it must be declared in the static configuration.\n\nPlugins are parsed and loaded exclusively during startup, which allows Traefik to check the integrity of the code and catch errors early on.\nIf an error occurs during loading, the plugin is disabled.\n\nFor security reasons, it is not possible to start a new plugin or modify an existing one while Traefik is running.\n\nOnce loaded, middleware plugins behave exactly like statically compiled middlewares.\nTheir instantiation and behavior are driven by the dynamic configuration.\n\nPlugin dependencies must be [vendored](https://golang.org/ref/mod#vendoring) for each plugin.\nVendored packages should be included in the plugin's GitHub repository. ([Go modules](https://blog.golang.org/using-go-modules) are not supported.)\n\n### Configuration\n\nFor each plugin, the Traefik static configuration must define the module name (as is usual for Go packages).\n\nThe following declaration (given here in YAML) defines a plugin:\n\n```yaml\n# Static configuration\n\nexperimental:\n  plugins:\n    example:\n      moduleName: github.com/traefik/plugindemo\n      version: v0.2.1\n```\n\nHere is an example of a file provider dynamic configuration (given here in YAML), where the interesting part is the `http.middlewares` section:\n\n```yaml\n# Dynamic configuration\n\nhttp:\n  routers:\n    my-router:\n      rule: host(`demo.localhost`)\n      service: service-foo\n      entryPoints:\n        - web\n      middlewares:\n        - my-plugin\n\n  services:\n   service-foo:\n      loadBalancer:\n        servers:\n          - url: http://127.0.0.1:5000\n  \n  middlewares:\n    my-plugin:\n      plugin:\n        example:\n          headers:\n            Foo: Bar\n```\n\n### Local Mode\n\nTraefik also offers a developer mode that can be used for temporary testing of plugins not hosted on GitHub.\nTo 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](https://golang.org/doc/gopath_code.html#Workspaces), which can be the local GOPATH or any directory.\n\nThe plugins must be placed in `./plugins-local` directory,\nwhich should be in the working directory of the process running the Traefik binary.\nThe source code of the plugin should be organized as follows:\n\n```\n./plugins-local/\n    └── src\n        └── github.com\n            └── traefik\n                └── plugindemo\n                    ├── demo.go\n                    ├── demo_test.go\n                    ├── go.mod\n                    ├── LICENSE\n                    ├── Makefile\n                    └── readme.md\n```\n\n```yaml\n# Static configuration\n\nexperimental:\n  localPlugins:\n    example:\n      moduleName: github.com/traefik/plugindemo\n```\n\n(In the above example, the `plugindemo` plugin will be loaded from the path `./plugins-local/src/github.com/traefik/plugindemo`.)\n\n```yaml\n# Dynamic configuration\n\nhttp:\n  routers:\n    my-router:\n      rule: host(`demo.localhost`)\n      service: service-foo\n      entryPoints:\n        - web\n      middlewares:\n        - my-plugin\n\n  services:\n   service-foo:\n      loadBalancer:\n        servers:\n          - url: http://127.0.0.1:5000\n  \n  middlewares:\n    my-plugin:\n      plugin:\n        example:\n          headers:\n            Foo: Bar\n```\n\n## Defining a Plugin\n\nA plugin package must define the following exported Go objects:\n\n- A type `type Config struct { ... }`. The struct fields are arbitrary.\n- A function `func CreateConfig() *Config`.\n- A function `func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)`.\n\n```go\n// Package example a example plugin.\npackage example\n\nimport (\n\t\"context\"\n\t\"net/http\"\n)\n\n// Config the plugin configuration.\ntype Config struct {\n\t// ...\n}\n\n// CreateConfig creates the default plugin configuration.\nfunc CreateConfig() *Config {\n\treturn \u0026Config{\n\t\t// ...\n\t}\n}\n\n// Example a plugin.\ntype Example struct {\n\tnext     http.Handler\n\tname     string\n\t// ...\n}\n\n// New created a new plugin.\nfunc New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {\n\t// ...\n\treturn \u0026Example{\n\t\t// ...\n\t}, nil\n}\n\nfunc (e *Example) ServeHTTP(rw http.ResponseWriter, req *http.Request) {\n\t// ...\n\te.next.ServeHTTP(rw, req)\n}\n```\n\n## Logs\n\nCurrently, the only way to send logs to Traefik is to use `os.Stdout.WriteString(\"...\")` or `os.Stderr.WriteString(\"...\")`.\n\nIn the future, we will try to provide something better and based on levels.\n\n## Plugins Catalog\n\nTraefik plugins are stored and hosted as public GitHub repositories.\n\nEvery 30 minutes, the Plugins Catalog online service polls Github to find plugins and add them to its catalog.\n\n### Prerequisites\n\nTo be recognized by Plugins Catalog, your repository must meet the following criteria:\n\n- The `traefik-plugin` topic must be set.\n- The `.traefik.yml` manifest must exist, and be filled with valid contents.\n\nIf your repository fails to meet either of these prerequisites, Plugins Catalog will not see it.\n\n### Manifest\n\nA manifest is also mandatory, and it should be named `.traefik.yml` and stored at the root of your project.\n\nThis YAML file provides Plugins Catalog with information about your plugin, such as a description, a full name, and so on.\n\nHere is an example of a typical `.traefik.yml`file:\n\n```yaml\n# The name of your plugin as displayed in the Plugins Catalog web UI.\ndisplayName: Name of your plugin\n\n# For now, `middleware` is the only type available.\ntype: middleware\n\n# The import path of your plugin.\nimport: github.com/username/my-plugin\n\n# A brief description of what your plugin is doing.\nsummary: Description of what my plugin is doing\n\n# Medias associated to the plugin (optional)\niconPath: foo/icon.png\nbannerPath: foo/banner.png\n\n# Configuration data for your plugin.\n# This is mandatory,\n# and Plugins Catalog will try to execute the plugin with the data you provide as part of its startup validity tests.\ntestData:\n  Headers:\n    Foo: Bar\n```\n\nProperties include:\n\n- `displayName` (required): The name of your plugin as displayed in the Plugins Catalog web UI.\n- `type` (required): For now, `middleware` is the only type available.\n- `import` (required): The import path of your plugin.\n- `summary` (required): A brief description of what your plugin is doing.\n- `testData` (required): Configuration data for your plugin. This is mandatory, and Plugins Catalog will try to execute the plugin with the data you provide as part of its startup validity tests.\n- `iconPath` (optional): A local path in the repository to the icon of the project.\n- `bannerPath` (optional): A local path in the repository to the image that will be used when you will share your plugin page in social medias.\n\nThere should also be a `go.mod` file at the root of your project. Plugins Catalog will use this file to validate the name of the project.\n\n### Tags and Dependencies\n\nPlugins Catalog gets your sources from a Go module proxy, so your plugins need to be versioned with a git tag.\n\nLast but not least, if your plugin middleware has Go package dependencies, you need to vendor them and add them to your GitHub repository.\n\nIf something goes wrong with the integration of your plugin, Plugins Catalog will create an issue inside your Github repository and will stop trying to add your repo until you close the issue.\n\n## Troubleshooting\n\nIf Plugins Catalog fails to recognize your plugin, you will need to make one or more changes to your GitHub repository.\n\nIn order for your plugin to be successfully imported by Plugins Catalog, consult this checklist:\n\n- The `traefik-plugin` topic must be set on your repository.\n- There must be a `.traefik.yml` file at the root of your project describing your plugin, and it must have a valid `testData` property for testing purposes.\n- There must be a valid `go.mod` file at the root of your project.\n- Your plugin must be versioned with a git tag.\n- If you have package dependencies, they must be vendored and added to your GitHub repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraefik%2Fplugindemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraefik%2Fplugindemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraefik%2Fplugindemo/lists"}