Help us shape the future of Go! Take the 2026 Go Developer Survey

templates

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package templates is the one place an email Template is listed, read, written and deleted. Handlers on /site and /api stay thin adapters: scope check, call, map. Transactional send reads a Template through Get, by reference (ADR 0005); copy-at-author-time (ADR 0003) is marketing only and lives elsewhere.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound: no such Template in this Workspace.
	ErrNotFound = validation.Refuse("templates: template not found", "errors.template_not_found")
	// ErrBlankName: the Template name is blank.
	ErrBlankName = validation.Refuse("templates: name must not be empty", "errors.name_empty")
	// ErrBodyAndDoc: a write carries both a body and a document. A client writes one of them: the
	// document (the server builds the body from it) or the body (which clears the document).
	ErrBodyAndDoc = validation.Refuse("templates: write a body or a doc, not both", "errors.body_and_doc")
)

Domain errors. Callers match with errors.Is.

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name    string
	Subject *string
	Body    *string
	// Doc is the editor's JSON document, empty when the Template is written as HTML. The body is
	// built from it in the same save (ADR 0040).
	Doc json.RawMessage
	// Prepared is Doc already rendered by emailrender.FromDocument, for a caller that renders
	// before it opens a transaction so that no database connection is held through the render.
	// Nil renders Doc here; a Body is never combined with it.
	Prepared *emailrender.Authored
}

CreateInput is a new Template; nil Subject and Body keep their defaults.

type Module

type Module struct{}

Module holds no state: every call receives the Workspace-scoped client (ADR 0017).

func New

func New() *Module

New builds the templates module.

func (*Module) Create

func (m *Module) Create(ctx context.Context, s *ent.Scoped, in CreateInput) (*ent.EmailTemplate, error)

Create stores a Template. A blank name is ErrBlankName; a subject, body or document that cannot render is emailrender.ErrInvalidContent; the body is stored sanitized.

func (*Module) Delete

func (m *Module) Delete(ctx context.Context, s *ent.Scoped, id int64) error

Delete removes a Template.

func (*Module) Get

func (m *Module) Get(ctx context.Context, s *ent.Scoped, id int64) (*ent.EmailTemplate, error)

Get returns one Template of the Workspace.

func (*Module) List

List returns a page of the Workspace's Templates, ascending by id (a catalogue).

func (*Module) Update

func (m *Module) Update(ctx context.Context, s *ent.Scoped, id int64, in UpdateInput) (*ent.EmailTemplate, error)

Update applies the given fields. A blank name is ErrBlankName.

type UpdateInput

type UpdateInput struct {
	Name    *string
	Subject *string
	Body    *string
	Doc     json.RawMessage
}

UpdateInput changes a Template; nil fields are left as they are. A Doc is rendered to the body in the same save and stored with it; a Body alone clears the stored document, so the two never disagree.

Jump to

Keyboard shortcuts

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