caddy icon indicating copy to clipboard operation
caddy copied to clipboard

httpError template function not documented

Open iUnknwn opened this issue 2 years ago • 1 comments

The Caddy template library includes the function httpError to return a status code like 404 when processing a template. This function is used on Caddy's own documentation website code.

However, the function isn't included in the Caddy template function list: https://caddyserver.com/docs/modules/http.handlers.templates

It would be great if this was included in the documentation - being able to return errors (particularly 404 errors) from templates is quite useful.

iUnknwn avatar Aug 08 '22 21:08 iUnknwn

Oh yeah, it's because it didn't work until Go ... 1.17 or 1.18 I think? So we left it undocumented. Probably time to document it now though.

mholt avatar Aug 08 '22 21:08 mholt

I would like to work on this. If possible can anyone guide me through it and can you assign me this issue if no one is working on it currently

Malankar avatar Aug 18 '22 04:08 Malankar

@Malankar Sure. Here's the function to be documented, for reference:

https://github.com/caddyserver/caddy/blob/c7772588bd44ceffcc0ba4817e4d43c826675379/modules/caddyhttp/templates/tplcontext.go#L400-L402

Here's where the documentation comment is:

https://github.com/caddyserver/caddy/blob/c7772588bd44ceffcc0ba4817e4d43c826675379/modules/caddyhttp/templates/templates.go#L34-L262

That comment just needs to be updated to add this function. Remember it is formatted using Markdown.

mholt avatar Aug 18 '22 14:08 mholt

@mholt I have made the necessary changes should I make a pull request

https://github.com/Malankar/caddy/blob/document/modules/caddyhttp/templates/templates.go#L191-L201

Malankar avatar Aug 19 '22 07:08 Malankar

Yes, please make a pull request.

Please use leading spaces at the start of every line of comments. See the surrounding comments, which all have this leading space.

francislavoie avatar Aug 21 '22 10:08 francislavoie

Thanks for the guidance @mholt and @francislavoie

Malankar avatar Aug 21 '22 12:08 Malankar