Access to Caddyfile's path in plugin's setup

I need to open a file from the plugin’s setup function. I want this filename to be relative to the location of the Caddyfile (well Corefile in this case). This information is available, but not exported.

The setup function gets a *caddy.Controller which has an *Instance, which has a caddyFileInput on which I could potentially do a FilePath, but… as said… all private fields. Is there another way that I’m overlooking?

Call Instance.Caddyfile() which gives you the Input which has a method to get the Path() to the origin Caddyfile (or Corefile).

Note that this won’t apply if the file is loaded some other way (via the network or an API or something).

Ack and thanks.

Hmm “loaded some other way”… indeed. That complicates matters a bit…

Yeah that’s why I don’t recommend making things relative to the Caddyfile. Good luck! :slight_smile:

Actually I’m looking more and more at exporting the Instance field on the Controller, since it could be useful for middlewares to be able to control when the Instance restarts or something (but I also don’t want to let people be able to shoot themselves in the foot).

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.