infogulch / xtemplate

A html/template-based hypertext preprocessor and rapid application development web server written in Go.
Apache License 2.0
73 stars 1 forks source link

Feature request: mail function #5

Open taophp opened 5 months ago

taophp commented 5 months ago

Currently, I see no way to handle mailing within xtemplate. And I don't think any ambitious web site or app should avoid this nowadays. So I'm sharing my thoughts about it below. Please, let me know what you think.

infogulch commented 5 months ago

This is a great idea!

I'm currently refactoring the dot context system to allow for start-time configuration of the dot value {{ . }}. This will unify the files context and db items so they are more configurable (including disabling entirely, or having more than one of each with different configurations), and will also allow for easier extensibility by importing a package that adds new functionality to the dot value. This is where I think mail functionality would fit best.

As for the Caddy integration, reusing the same configuration format as Caddy Security seems very reasonable. Caddy Security may be a good place to draw ideas for implementation as well.

taophp commented 5 months ago

Great ! Please, let me know how you progress on this!

infogulch commented 5 months ago

I have an update on the new dot value system.

Initially my plan was to use the reflect package to create a new struct at start time with (optionally) embedded fields configured by the user. This would give a nice UX where users could call methods on any of the embedded members directly, or prefix with the field name if ambiguous.

It turns out Go has very little support for creating structs with embedded members at start time. Here's some playground examples that show a few variations of what I tried:

This is a bit disappointing for me, and while its tempting to start yak shaving and submit implementation ideas on the upstream issue, for the sake of xtemplate it's probably best to accept that embedded fields are not feasible and just proceed with named fields. This hits the UX a bit, since all of the methods would have to be prefixed with their field name, but it's a small price to pay when the alternatives are "no user customization" and "wait until an issue from 2016 is fixed by the language". (And honestly there may be a clarity argument as well, since embedded fields are a moderately advanced Go feature.)

Long story short, if Go adds support for runtime embedded field methods then we'll have some options open to us in the future; until then I have a solid plan and a decent start at an implementation for xtemplate.