Is setup function called more than once?

Hey!

When our plugin is configured, the setup function is called only once or called each time the directive appears in Caddyfile?

If it is called only once, how should I know which config refers to each site (and request)?

Thanks :smiley:

I am experiencing same behaviour on 0.9. My plugin setup function is being called twice.

It is called once for every key in the head of the block it appears in. For example, if your directive is called gizmo:

key1, key2, key3 {
    gizmo foobar
}

Then your setup function will be called 3 times, one for each key. (For the HTTP server, the key is a site address.) You can access the key (site address) via c.Key.

If you have:

key1, key2, key3 {
    gizmo foo
    gizmo bar
}

Then it is still called only 3 times because the tokens will be combined together. This is why you must loop over the tokens with for c.Next(), since that call consumes the token with the text of “gizmo” each time.

Hope that makes sense.

1 Like

Oops. False Alarm.

1 Like

My browser betrayed me. I’ve responded “False Alarm” long ago.