github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/plugins/README.md (about) 1 # Extending Janus 2 3 Janus can be extended with plugins. Plugins add missing functionality to Janus. They are "plugged in" at compile-time. 4 The plugins are attached to an [API Definition](../api-definition/README.md) and you can enable or disable them at 5 any time. 6 7 Janus comes with a set of built in plugins that you can add to your API Definitions: 8 9 * [CORS](cors.md) 10 * [OAuth2](oauth.md) 11 * [Rate Limit](rate_limit.md) 12 * [Request Transformer](request_transformer.md) 13 * [Compression](compression.md) 14 15 ## How can I create a plugin? 16 17 Even though there are different kinds of plugins, the process of creating one is roughly the same for all. 18 19 ### 1. Create a package and register your plugin. 20 21 Start a new Go package with an init function and register your plugin with Janus: 22 23 ```go 24 import "github.com/hellofresh/janus/pkg/plugin" 25 26 func init() { 27 // register a "generic" plugin, like a directive or middleware 28 plugin.RegisterPlugin("name", myPlugin) 29 } 30 ``` 31 32 Every plugin must have a name and, when applicable, the name must be unique. 33 34 ### 2. Plug in your plugin. 35 36 To plug your plugin into Janus, import it. This is usually done near the top of [loader.go](../../pgk/loader/loader.go): 37 38 ```go 39 import _ "your/plugin/package/path/here" 40 ``` 41 42 ### 3. Write Tests! 43 44 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. 45 46 ### 4. Maintain your plugin. 47 48 People will use plugins that are useful, clearly documented, easy to use, and maintained by their owner. 49 And congratulations, you're a Janus plugin author!