Same directive multiple times for plugins

Hey, is it possible to define a directive as an array that can be called many times? and if possible, how can I do that .

For example:

caddy_module {
    some_directive 123
    some_directive 456

Thank you !

Yes, but what are you actually trying to do? :thinking:

I want to split Coraza configuration into multiple files:

include "variables.conf"
include "rules.conf"

For example

You’ll need to be more specific.

Are you asking this from the perspective of building a custom module? Or are you asking about a specific directive that already exists in Caddy?

Ultimately, JSON is the underlying configuration language for Caddy. The Caddyfile is just a UX wrapper to make it easier to configure. If you need to repeat the same option multiple times, just make sure that option is stored as a JSON array so it can repeated. And in the Caddyfile parsing step, just append to that slice.

You can find many examples in Caddy’s core that work like this, for example the path matcher (look for MatchPath).

Thank you for your answer, if that is the case I will think about something different like:

include "file1" "file2" "file3"

I still don’t understand your question, and I feel like you misunderstood my answer.

Could you please clarify what you’re trying to do? Please be specific.

1 Like

As far as I’m aware, there’s nothing stopping a non-terminating handler from being called as many times as you like, in succession, with different parameters, in either the Caddyfile or JSON config.

It’s completely up to the author of the module as to how their handler… handles… successive calls like this.

As @francislavoie mentioned, matchers in general are a good example of the versatility here.

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.