📗
Janus Manual
  • Introduction
  • Installation
    • Docker
  • Quick Start
    • Authenticating
    • Add an endpoint
    • Modify (Update/Delete) an endpoint
    • Add Plugins
    • Authentication
    • Adding your API - File System
  • Clustering/HA
  • Proxy Reference
    • Terminology
    • Overview
    • Routing capabilities
    • Load Balacing
    • Request Host header
      • Using wildcard hostnames
      • The preserve_host property
    • Request URI
      • The strip_path property
      • The append_path property
    • Request HTTP method
    • Routing priorities
    • Conclusion
  • Plugins
    • Basic
    • Organization
    • Body Limit
    • Circuit Breaker
    • Compression
    • CORS
    • OAuth
    • Rate Limit
    • Request Transformer
    • Response Transformer
    • Retry
  • Auth
    • OAuth 2.0
  • Misc
    • Health Checks
    • Monitoring
    • Tracing
  • Known Issues
    • Stale HTTP Keep-Alive
  • Upgrade Notes
    • 2.x to 3.x
    • 3.6.x to 3.7.x
Powered by GitBook
On this page
  • How can I create a plugin?
  • 1. Create a package and register your plugin.
  • 2. Plug in your plugin.
  • 3. Write Tests!
  • 4. Maintain your plugin.

Was this helpful?

Plugins

PreviousConclusionNextBasic

Last updated 4 years ago

Was this helpful?

Janus can be extended with plugins. Plugins add missing functionality to Janus. They are "plugged in" at compile-time. The plugins are attached to an and you can enable or disable them at any time.

Janus comes with a set of built in plugins that you can add to your API Definitions:

How can I create a plugin?

Even though there are different kinds of plugins, the process of creating one is roughly the same for all.

1. Create a package and register your plugin.

Start a new Go package with an init function and register your plugin with Janus:

import "github.com/hellofresh/janus/pkg/plugin"

func init() {
    // register a "generic" plugin, like a directive or middleware
    plugin.RegisterPlugin("name", myPlugin)
}

Every plugin must have a name and, when applicable, the name must be unique.

2. Plug in your plugin.

import _ "your/plugin/package/path/here"

3. Write Tests!

Write tests. Get good coverage where possible, and make sure your assertions test what you think they are testing! Use go vet and go test -race to ensure your plugin is as error-free as possible.

4. Maintain your plugin.

People will use plugins that are useful, clearly documented, easy to use, and maintained by their owner. And congratulations, you're a Janus plugin author!

To plug your plugin into Janus, import it. This is usually done near the top of :

API Definition
CORS
OAuth2
Rate Limit
Request Transformer
Compression
loader.go