plugins middleware

Plugins are handlers that satisfy the http.Handler.

They are declared in the routes section of the configuration file for example:

    plugins: # the order of the plugins meters
        - requestid
        - waf
        - cors
        - prometheus

  cors: ["", "cors.CORS"]
  csrf: ["", "csrf.CSRF"]
  prometheus: ["", "prometheus.Prometheus"]
  requestid: ["", "requestid.RequestID"]
  waf: ["", "waf.WAF"]

The plugins section is a list of plugins each of one defined within a list, for example:

- ["", "myplugin.MyPlugin"]

In this case, the first element of the list, should be the path/url where the plugin is located and that could be used as an import path:

The second part:


Corresponds to the way the plugin should be called.

Example of a plugin

This plugin only adds a header, in practices something more useful would be used.

package myplugin

import (

func MyPlugin(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("my-plugin", "testing slashquery")
		next.ServeHTTP(w, r)

make CONF=/path/to/slashquery.yml

When generating the routes, the routes.go file will include the source and Method of the plugin, for example:

// Code generated by genroutes.go at:
// 2017-06-04 18:26:31.466696196 +0200 CEST
// using data from
// examples/slashquery.yml
package slashquery

import (


// AddRoutes create router routes
func (sq *Slashquery) AddRoutes(router *violetear.Router) {
	router.Handle("test-myplugin/*", middleware.New(myplugin.MyPlugin).Then(sq.Proxy("test-myplugin")))

The current Makefile uses goimports to add or remove import lines.

comments powered by Disqus