Folks, I’m trying to test a simple custom plugin, I created a module that reads a config file and gets an access token from azure. I want to call this module then an endpoint is invoked. I wrote a test program in go that tests the module and it does return the token OK. My problem is calling the module from my caddyfile. The module is registered as http.handlers.azureauth and in my caddyfile I call azureauth but I get Caddyfile:11: unrecognized directive: azureauth
My caddyfile is this:
{
# Optional global options block
}
:8080 { @somePath {
path /test
}
# Use the AzureAuth handler to retrieve the token
azureauth {
token {
# This section could be empty if you are loading from config
# It will use the AzureToken struct's Provision method to load the token info
}
}
# Handle requests to the /test endpoint
handle @somePath {
# Call the next handler after setting the token in the header
respond "Token retrieved successfully" 200
}
# Add other handlers as needed
How are you running Caddy? Make sure that your plugin is compiled in first. Typically, xcaddy run is what you’ll use for testing while developing your plugin. It does this for you.
Also, where’s your plugin code? Make sure to register your directive.
Hi @matt , to be honest I’ve tried many different ways but I’ve gone simple following the tutorial and I get the same error. Writing a Caddy Plugin Part II | 萌え豚's Blog
The error is
C:\dev\caddy\caddy-hello>dir
Volume in drive C is Windows-SSD
Volume Serial Number is A224-C1F2
Please mind your post’s formatting. It’s hard to follow because you didn’t use code blocks for file/log content. Use the </> button and put the contents between the ```
I don’t see anywhere in your post that you use xcaddy. See this program:
Did you try following this guide?
After that, read this one to understand how to parse Caddyfile config for your plugin:
Show the actual Go code you’re writing as well, if you still can’t get it working.
That’s still only half the story. Show your module code.
Normally Go packages have an ID like github.com/your-username/package.
caddy_hello is certainly not a standard module, so I don’t understand that output. Are you editing that at all? Please don’t, show the actual output.
Well, without seeing your code nor your Caddyfile, I don’t know what to tell you. Also, that’s definitely not the entire error message, it would be a much longer error message than that (with the line number in your Caddyfile etc).
2024/09/28 22:57:21 [INFO] exec (timeout=0s): C:\Program Files\Go\bin\go.exe get -d -v
go: -d flag is deprecated. -d=true is a no-op
go: caddy imports
caddy-hello: package caddy-hello is not in std (C:\Program Files\Go\src\caddy-hello)
2024/09/28 22:57:22 [FATAL] exit status 1
Please put everything in code blocks, don’t use quote blocks for anything like logs. Code blocks preserve the text and indentation, quotes don’t and cause things like Markdown rendering to occur so it messes up anything that looks like a link etc. Notice how messy your post looks because of that.
Ah, you’re trying to declare a global option. In that case, you must put your config within the global options block, it can’t be top level. So it should look like this: