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

site

package
v0.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package site is the public front controller: it maps public URLs to content, terms and listings and renders them through the active theme (theme.Service). It also serves theme assets, sitemap.xml/robots.txt (via seo.Service) and the contact form.

Index

Constants

View Source
const (
	SettingFormsNotify     = "forms.notify"              // bool, default true: mail each stored submission
	SettingFormsRecipients = "forms.recipients"          // "a@x.com, b@y.com"; empty: contact.email, else the first admin
	SettingAttachments     = "contact.attachments"       // bool, default false: accept one file per submission
	SettingAttachmentMaxMB = "contact.attachment_max_mb" // 1–20, default 5

)

Form settings. The contact.* flags are public (themes read them with {{setting}} to show the file input); forms.* stay private because the recipient list holds staff addresses.

View Source
const DefaultPolicyDirectory = "/var/lib/gorun-site-policies"

DefaultPolicyDirectory is the root-owned directory GORUN_SITE_POLICY files must live in, unless a build sets another one with SetPolicyDirectory.

View Source
const (
	// HookFormSubmitted is emitted (async) for every accepted form
	// submission; the site module itself subscribes (deliverForm) and mails
	// it to contact.email through the mailer service.
	HookFormSubmitted = "site.form.submitted"
)
View Source
const KindFormResult = "form-result"

KindFormResult is the theme kind rendered after a form submission.

View Source
const PermIntakeReview = "intake.review"
View Source
const (
	// PermSubmissions guards System → Form submissions (an existing
	// permission: no new grant needed).
	PermSubmissions = "settings.manage"
)
View Source
const SettingAvailability = "site.availability"
View Source
const SettingContactEmail = "contact.email"

SettingContactEmail is the recipient of contact form messages; when it is unset or invalid the first active admin's email is used.

View Source
const SettingMaintenance = "site.maintenance"

SettingMaintenance (bool) puts the public site in maintenance: every public page answers 503 with a short notice, while the admin, the API, MCP, /healthz, the sitemap, robots.txt, media and theme assets keep working.

Variables

View Source
var ErrFormSetting = errors.New("invalid form setting")

ErrFormSetting is wrapped by every ValidateFormSetting rejection.

FormSettingKeys lists the keys ValidateFormSetting accepts.

Functions

func SetPolicyDirectory

func SetPolicyDirectory(dir string)

SetPolicyDirectory sets the trusted policy directory for this process. It is a build-time choice (call it from main before Boot), not configuration: the directory is a trust root, so it never comes from the environment. An empty or relative dir is ignored.

func ValidateFormSetting

func ValidateFormSetting(key, text string) (any, error)

ValidateFormSetting validates one form setting given as text (the admin form, `gorun settings set`) and returns the value to store: a bool for the flags, an int for the size and a normalised list for recipients.

Types

type Availability

type Availability struct {
	SiteID       string     `json:"site_id,omitempty"`
	Revision     int64      `json:"revision"`
	Mode         string     `json:"mode"`
	Message      string     `json:"message"`
	PasswordHash string     `json:"password_hash,omitempty"`
	PageRules    []PageRule `json:"page_rules,omitempty"`
}

type FormState

type FormState struct {
	OK     bool
	Errors map[string]string // field → i18n key
	Values map[string]string
	Back   string
}

FormState is passed to form-result.html as .Extra.form.

type FormSubmission

type FormSubmission struct {
	ID             string `json:"id"` // form_submissions row
	Form           string `json:"form"`
	Name           string `json:"name"`
	Email          string `json:"email"`
	Message        string `json:"message"`
	Page           string `json:"page"`
	IP             string `json:"ip"`
	SubmittedAt    string `json:"submitted_at"`
	AttachmentName string `json:"attachment_name,omitempty"`
	AttachmentType string `json:"attachment_type,omitempty"`
	AttachmentSize int64  `json:"attachment_size,omitempty"`
}

FormSubmission is the HookFormSubmitted payload. It carries attachment metadata only; delivery reads the file from <data>/form-uploads/<id>.

type Module

type Module struct{}

Module is the site kernel.Module. It registers after redirects, so the redirects middleware (Router.Public.Use) already wraps these routes.

func New

func New() *Module

New returns the site module.

func (*Module) Catalogs

func (*Module) Catalogs() fs.FS

Catalogs implements kernel.CatalogProvider.

func (*Module) Migrations

func (*Module) Migrations() fs.FS

Migrations implements kernel.Module (form_submissions).

func (*Module) Name

func (*Module) Name() string

Name implements kernel.Module.

func (*Module) Register

func (*Module) Register(d *kernel.Deps) error

Register mounts the public routes. Specific routes come first; GET /* dispatches everything else (archives, singles, terms, pages, 404). Routes rendering forms pass through auth.CSRFMiddleware (on these routes only, never Public.Use: other modules' public POSTs have their own rules); POST /forms/contact first passes contactGuard.

type PageRule

type PageRule struct {
	ContentID    string `json:"content_id"`
	Mode         string `json:"mode"`
	Message      string `json:"message"`
	PasswordHash string `json:"password_hash,omitempty"`
	Revision     int64  `json:"revision"`
}

type Submission

type Submission struct {
	FormSubmission
	Source                          formSource
	Status, Delivery, DeliveryError string
}

Submission is one stored form_submissions row: the submission as posted (SubmittedAt is the row's created_at) plus its inbox state.

func (Submission) SizeText

func (s Submission) SizeText() string

SizeText is the attachment size for display.

Jump to

Keyboard shortcuts

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