utils

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadTemplate added in v1.1.0

func LoadTemplate(path string) (*template.Template, error)

LoadTemplate parses and caches an HTML template file by its path. The path is canonicalized so "./template.html" and "template.html" share a cache entry.

func ParseAddressInput added in v1.1.0

func ParseAddressInput(input string) ([]string, error)

ParseAddressInput to parse --cc / --bcc from inline or file input. If the input is an existing file path, it reads emails from the file. Otherwise, it treats the input as comma-separated emails.

func ReadTextInput added in v1.0.0

func ReadTextInput(textArg string) (string, error)

ReadTextInput returns the body from inline --text or file path. It checks if the argument is an existing file path, otherwise treats it as inline text.

func RenderTemplate added in v1.1.0

func RenderTemplate(recipient parser.Recipient, templatePath string) (string, error)

RenderTemplate renders an HTML template with the given recipient's data. Recipient fields are accessible in templates as {{ .email }}, {{ .name }}, etc.

func SplitAndTrim added in v1.0.0

func SplitAndTrim(s string) []string

SplitAndTrim splits comma-separated string and trims whitespace from each email.

func StartPreviewServer added in v1.1.0

func StartPreviewServer(rendered string, port int) error

StartPreviewServer starts a local HTTP server to preview the rendered email. Returns an error if the server fails to start or serve.

Types

type TemplateCache added in v1.1.0

type TemplateCache struct {
	// contains filtered or unexported fields
}

TemplateCache is a bounded, TTL-based cache for parsed templates. Keys are canonical (absolute) file paths.

func (*TemplateCache) Get added in v1.1.0

func (tc *TemplateCache) Get(path string) (*template.Template, bool)

Get returns the cached template for path, or (nil, false) if absent or expired. Expired entries are removed on detection so they don't linger in the cache.

func (*TemplateCache) Set added in v1.1.0

func (tc *TemplateCache) Set(path string, tmpl *template.Template)

Set stores a parsed template under the given (already canonicalized) path. If the cache is full, the oldest entry is evicted first.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL