email

package module
v0.0.0-...-7243c35 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package email provides frontmatter parsing and serialization using email-style headers (RFC 822-inspired key: value pairs).

This format is unusual among SSGs but offers a few advantages: it is human-writable without indentation rules, supports comments via lines starting with '#', and requires no external dependencies.

Example frontmatter:

Title: My Post
Date: 2024-01-15
Tags: go, ssg, web
# this is a comment

<body content starts after the blank line>

Index

Constants

This section is empty.

Variables

View Source
var Loader = NewLoader()

Loader is the default MetaLoader for email-style frontmatter with no value transformers. Use NewLoader to apply transformers such as AsList.

Functions

func ApplyTransforms

func ApplyTransforms(k string, v any, tx []ValueTransformer) (any, error)

ApplyTransforms runs tx in order against (k, v). If any transformer returns io.EOF, that value is used and iteration stops.

func Marshal

func Marshal(data map[string]any) ([]byte, error)

Marshal serializes a map[string]any into email-header style output. Nested maps are written with dotted key prefixes (e.g. "author.name: foo").

func NewLoader

func NewLoader(tx ...ValueTransformer) func([]byte) (map[string]any, []byte, error)

NewLoader returns a MetaLoader for email-style frontmatter, applying tx in order to each parsed key/value pair.

email.NewLoader(email.AsList("Tags"))

func Set

func Set(kv map[string]any, k string, v any, tx []ValueTransformer) error

Set writes k/v into kv, applying any transformers first. Supports dotted keys (e.g. "author.name") to create nested maps.

func Unmarshal

func Unmarshal(src []byte, out map[string]any, tx ...ValueTransformer) error

Unmarshal parses email-style headers from src into out. Lines starting with '#' are treated as comments and ignored. A line indented with a space or tab continues the previous value.

Types

type ValueTransformer

type ValueTransformer func(k string, v any) (any, error)

ValueTransformer is a function that can inspect or transform a parsed key/value pair. Return io.EOF to signal the value has been fully handled and no further transformers should run.

func AsList

func AsList(key string) ValueTransformer

AsList returns a ValueTransformer that parses the named key's value as a CSV list rather than a plain string.

Jump to

Keyboard shortcuts

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