Golang plugin: Store and read custom conf: Best practices

We’d like to store some custom config for our golang plugin. Seeking advice re best practice and also some implementation guidance (go and tyk newbies here).

We found documentation that references reading conf files by providing a path. That seems like a maintenance risk. Does tyk support creating a custom config file that can be included such that it’s merged into the runtime config on gateway start, either directly into tyk.conf or api specific conf files?

Thanks!

Hi,

Thanks for your question:

Best practice varies with deployment method. What’s best with Tyk deployed in a VM or on physical hardware might not be best when deploying with kubernetes.

I’ll outline some of the options so you can decide what suits the local deployment best but because a plugin is a golang program the options are limitless.

Tyk doesn’t do this for you and it’s best to leave tyk.conf to configure the gateway rather than the plugin.

It is possible to use the config_data section in the API definition so control plugin behaviour. This is handy if you want the plugin to have API specific behaviours.

But if the plugin behaves the same way for all APIs, or it needs some global config to get it started then repeating the config_data in each API definition is tiresome and error prone.

For global config, use an init function in the plugin to setup global variables when the plugin is loaded. But where that init function pulls the config from is entirely up to you. You could use a secret store like vault, a config file, a database, or even environment variables.

Developing a plugin is not easy, most people who write custom go plugins are very experienced golang developers and both the documentation and support is targeted at that audience. This is because the difficulties are more to do with golang’s requirements on plugins than something implemented within Tyk.

There are some examples provided in Tyk’s github repos to help with getting started.

Cheers,
Pete