53deb8e9a8
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>
47 lines
1.6 KiB
Markdown
47 lines
1.6 KiB
Markdown
---
|
|
name: email_template_render
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func EmailTemplateRender(tmplStr string, data map[string]any) (string, error)"
|
|
description: "Renderiza un Go text/template con el data map dado y retorna el string resultante. Falla si el template tiene sintaxis invalida o si la ejecucion produce un error."
|
|
tags: [email, template, render, text/template]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: ["bytes", "fmt", "text/template"]
|
|
params:
|
|
- name: tmplStr
|
|
desc: "fuente del template en sintaxis Go text/template (ej: 'Hola {{.Name}}')"
|
|
- name: data
|
|
desc: "mapa de variables disponibles dentro del template (clave string, valor any)"
|
|
output: "string resultado del template renderizado con los datos provistos"
|
|
tested: true
|
|
tests:
|
|
- "renderiza template simple con datos"
|
|
- "sustituye multiples variables"
|
|
- "error en template invalido"
|
|
- "template vacio retorna string vacio"
|
|
test_file_path: "functions/infra/email_template_render_test.go"
|
|
file_path: "functions/infra/email_template_render.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
tmpl := "Hola {{.Name}}, tu pedido {{.OrderID}} esta listo."
|
|
body, err := EmailTemplateRender(tmpl, map[string]any{
|
|
"Name": "Alice",
|
|
"OrderID": "ORD-1234",
|
|
})
|
|
// body = "Hola Alice, tu pedido ORD-1234 esta listo."
|
|
```
|
|
|
|
## Notas
|
|
|
|
Usa `text/template` de la stdlib de Go. Para HTML con escape automatico usar `html/template` en su lugar. Util para generar el body de emails con datos dinamicos antes de llamar a `EmailBuildHTML` o `EmailBuildText`.
|