Files
fn_registry/functions/infra/email_template_render.go
T
egutierrez ef3ae2aae9 feat: tipos y funciones email SMTP en Go (infra)
Tipos: EmailAttachment, EmailMessage, SMTPConfig.
Puras: email_build_html, email_build_text, email_with_attachment, email_template_render.
Impuras: smtp_connect (TLS/STARTTLS/plain), smtp_send (MIME multipart con adjuntos).
Solo stdlib: net/smtp, crypto/tls, text/template, mime/multipart.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 02:01:13 +02:00

25 lines
758 B
Go

package infra
import (
"bytes"
"fmt"
"text/template"
)
// EmailTemplateRender executes a Go text/template with the given data map
// and returns the rendered string.
// tmplStr is the template source (Go text/template syntax).
// data is a map of string keys to any values available inside the template.
// Returns an error if the template fails to parse or execute.
func EmailTemplateRender(tmplStr string, data map[string]any) (string, error) {
tmpl, err := template.New("email").Parse(tmplStr)
if err != nil {
return "", fmt.Errorf("email_template_render: parse: %w", err)
}
var buf bytes.Buffer
if err := tmpl.Execute(&buf, data); err != nil {
return "", fmt.Errorf("email_template_render: execute: %w", err)
}
return buf.String(), nil
}