Question about Extending Caddy

Intro
Hello,

So I am extending Caddy and there are a couple of things I could not find adequate documentation for.

First I’ll explain what I need, so that it’ll be more logical for you to understand.

Explanation

I am making a custom JWT ware module to extend Caddy to accomodate my specific needs, and to experiment with creating modules. The module I create will accept subdirectives which define useful stuff for example, the key identifier and storage to lookup in.

If I want to register a reusable socket to the database, that’s a PLUS, otherwise every module I make that requries a DB connection, ill need to make DB connection in Provision method of every module, which can be difficult to maintain, and nerfs the scalability. For that reason, I’ve planned to first make an MongoDB App. In Caddy an App is something that Caddy needs to run. So I found it very logical.

Continuing from this, I know that a guest module can access any app from the context, but it is better to register it under the namespace of the app.

Now my confusion will start in a moment. I want to have support for Caddyfile, then the module directives can be given, but how to accept abritrary options to my App.

1 Like

I think I’ve found the answer after digging in the docs. I should just implement my own caddy.storage module: caddy.storage.mongo and just consume ctx.Storage in my authentication module.

And btw all what i said and i am doin is just to experiment with caddy plugins.

1 Like

Apps are currently configurable via global options. You can call RegisterGlobalOption to get a hook for when that option appears in the Caddyfile, then you produce an httpcaddyfile.App struct to carry the parsed JSON config. See modules/caddyevents/eventsconfig/caddyfile.go in the Caddy source for a practical example.

That is a valid option, but is the Storage interface sufficient for your needs? Do you need Mongo-specific APIs?

Do you want to use the same storage for Caddy’s data (certs/keys) as for your auth plugin?

1 Like

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