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

server

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 94 Imported by: 0

Documentation

Overview

Package server provides infrastructure initialization.

Package server provides the HTTP server and routing configuration.

Package server — CMS core route mounts.

This file holds the route mounters for what Hatamoto considers the "CMS core": entity / schema / media / forms / menus / redirects / public site rendering / auth + user management / taxonomy / analytics admin / linking / 404 monitor / API keys.

Package server — plugin extension point for the public sitemap.

Core derives its own groups from the schema URL settings (sitemap_builder.go). Plugins that re-add a content type with its own archive listing (e.g. case-study, playbook) register an archive group via RegisterArchiveGroup, and plugins that own a standalone funnel page register it via RegisterStaticSitemapRoute — both from their Wire(), which runs at boot before any request is served.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCountingHandler

func NewCountingHandler(inner slog.Handler) slog.Handler

NewCountingHandler wraps inner and counts the records RenderErrorCount reports.

func RegisterArchiveGroup

func RegisterArchiveGroup(groupKey string, cfg ArchiveGroupConfig)

RegisterArchiveGroup installs a plugin-owned sitemap archive group. The group is merged with the groups derived from schema settings when the sitemap is built; re-registering a key replaces its configuration.

func RegisterStaticSitemapRoute

func RegisterStaticSitemapRoute(e SitemapEntry)

RegisterStaticSitemapRoute installs a plugin-owned static URL into the "misc" sub-sitemap.

func RenderErrorCount

func RenderErrorCount() int64

RenderErrorCount is the render errors smoke requests have caused so far.

func RouteTable

func RouteTable() (table []httpx.Route, err error)

RouteTable returns every route the core registers (method, path, handler) for `hatamoto routes` and the route-table test. It builds the routes on a Server with just enough non-nil collaborators and no database, so plugin routes (which live on per-plugin muxes behind fixed catch-alls) are not listed: `hatamoto routes` prints that note.

func UpdatePlugins

func UpdatePlugins(pk *packages.Store) updater.PluginSource

UpdatePlugins is the preflight's view of the installed packages, for the command line as well as the server.

Types

type ArchiveGroupConfig

type ArchiveGroupConfig struct {
	PathPrefix       string
	SchemaSlugs      []string
	ArchiveIndexPath string
}

ArchiveGroupConfig describes a plugin-owned sitemap group.

type BreadcrumbItem struct {
	Label string `json:"label"`
	Href  string `json:"href"`
}

BreadcrumbItem represents a breadcrumb navigation item.

type ContentSegmentResponse

type ContentSegmentResponse struct {
	SegmentIndex      int      `json:"segment_index"`
	SegmentType       string   `json:"segment_type"`
	Heading           string   `json:"heading,omitempty"`
	ContentText       string   `json:"content_text"`
	ContentHTML       string   `json:"content_html,omitempty"`
	TopicLabels       []string `json:"topic_labels,omitempty"`
	IsAnswerCandidate bool     `json:"is_answer_candidate"`
	WordCount         int      `json:"word_count"`
}

ContentSegmentResponse represents a content segment in the public API.

type HrefLang

type HrefLang struct {
	Rel      string `xml:"rel,attr"`
	HrefLang string `xml:"hreflang,attr"`
	Href     string `xml:"href,attr"`
}

HrefLang represents an xhtml:link alternate element (added by plugin filters).

type Infrastructure

type Infrastructure struct {
	Cache            *cache.Cache
	CacheInvalidator *cache.CacheInvalidator
}

Infrastructure holds the in-process cache components.

func NewInfrastructure

func NewInfrastructure(logger *slog.Logger) *Infrastructure

NewInfrastructure builds the in-process cache and its invalidator.

func (*Infrastructure) Shutdown

func (i *Infrastructure) Shutdown() error

Shutdown releases infrastructure components. The in-process cache needs no teardown.

type NavigationItem struct {
	Label    string           `json:"label"`
	Href     string           `json:"href"`
	Target   string           `json:"target,omitempty"`
	Children []NavigationItem `json:"children,omitempty"`
}

NavigationItem represents a menu item.

type PageMeta

type PageMeta struct {
	Title        string `json:"title"`
	Description  string `json:"description,omitempty"`
	OGImage      string `json:"og_image,omitempty"`
	CanonicalURL string `json:"canonical_url,omitempty"`
	NoIndex      bool   `json:"no_index,omitempty"`
}

PageMeta represents SEO metadata for a page.

type PublicPageResponse

type PublicPageResponse struct {
	Entity     *entity.Entity           `json:"entity"`
	JSONLD     map[string]interface{}   `json:"json_ld,omitempty"`
	Meta       PageMeta                 `json:"meta"`
	Breadcrumb []BreadcrumbItem         `json:"breadcrumb"`
	Editorial  json.RawMessage          `json:"editorial,omitempty"`
	Segments   []ContentSegmentResponse `json:"segments,omitempty"`
	// AICrawlerComment is the HTML comment block embedded in the page for
	// AI/LLM crawlers. Empty when the entity has been opted out via the
	// SEO tab's "Include in /llms.txt" toggle.
	AICrawlerComment string `json:"ai_crawler_comment,omitempty"`
}

PublicPageResponse represents a public page API response.

type Server

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

Server represents the HTTP server.

func New

func New(cfg *config.Config, db *database.DB, logger *slog.Logger) *Server

New creates a new server instance.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler is the fully wired HTTP handler (site, API, MCP), for callers that drive the server without listening (tests).

func (*Server) NoUpdater

func (s *Server) NoUpdater(err error)

NoUpdater records why there is no update agent, for the Updates page.

func (*Server) SetBackups

func (s *Server) SetBackups(eng *backup.Engine)

SetBackups hands the server the backup engine and the admin its service. The routes are mounted in New, before the engine exists; call it before the server starts serving.

func (*Server) SetStats added in v1.0.2

func (s *Server) SetStats(svc *installstats.Service)

SetStats hands the install stats service to the server. Call it before Start. HATAMOTO_TELEMETRY=off is applied here, once, even when the worker is off, so a stored install ID is deleted at boot. The daily job is scheduled when the worker is on.

func (*Server) SetUpdater

func (s *Server) SetUpdater(env updater.Env) error

SetUpdater builds the update agent from env, adding what only the server knows (installed packages, site timezone), and puts its periodic check on the worker scheduler. Call it before Start. With the worker off, or the job disabled by WORKER_DISABLE_JOBS, nothing is scheduled; the agent is built anyway so a bad update URL is reported at boot.

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown gracefully stops the server.

func (*Server) Start

func (s *Server) Start() error

Start begins listening for HTTP requests.

type SitemapEntry

type SitemapEntry struct {
	Path       string
	Priority   float64
	ChangeFreq string
}

SitemapEntry is a plugin-owned static URL for the misc sitemap.

type SitemapIndex

type SitemapIndex struct {
	XMLName  xml.Name            `xml:"sitemapindex"`
	XMLNS    string              `xml:"xmlns,attr"`
	Sitemaps []SitemapIndexEntry `xml:"sitemap"`
}

SitemapIndex represents an XML sitemap index (container for sub-sitemaps).

type SitemapIndexEntry

type SitemapIndexEntry struct {
	Loc     string `xml:"loc"`
	LastMod string `xml:"lastmod,omitempty"`
}

SitemapIndexEntry represents a single sub-sitemap reference in the index.

type URL

type URL struct {
	Loc        string     `xml:"loc"`
	LastMod    string     `xml:"lastmod,omitempty"`
	ChangeFreq string     `xml:"changefreq,omitempty"`
	Priority   float64    `xml:"priority"`
	Links      []HrefLang `xml:"xhtml:link,omitempty"`
}

URL represents a single URL entry in the sitemap.

type URLSet

type URLSet struct {
	XMLName    xml.Name `xml:"urlset"`
	XMLNS      string   `xml:"xmlns,attr"`
	XMLNSXhtml string   `xml:"xmlns:xhtml,attr,omitempty"`
	URLs       []URL    `xml:"url"`
}

URLSet represents an XML sitemap with optional xhtml namespace for alternates.

Source Files

Jump to

Keyboard shortcuts

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