comments

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 7 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

modules/comments

Official Lesstruct module: the comment system — per-content discussion with moderation (pending/approved/rejected/spam).

Layout (module template)

module.go            # kernel.Module + Migrator (single registry-facing file)
migrations/          # {sqlite,postgresql,mysql}/000001_comments.{up,down}.sql (embed)
api/                 # browser handlers (legacy envelope) + mocks
api/agent/           # Bearer-realm handlers (UPPER_SNAKE envelope) + dto + mocks
domain/              # service, entities, validation, repository interfaces (3.3b)
domain/mocks/        # CommentRepository testify mock (moved with the domain)
store/               # single-source repository on kernel.Dialect (3.3c)
admin/               # admin-shell manifest (comments moderation entry)
testutil/            # kernel fixture for module tests

Handlers

Both auth realms are served from this module: api.CommentHandler (browser JWT/CSRF, legacy error:null envelope) and api/agent.CommentHandler (Bearer API key, UPPER_SNAKE envelope). Content lookups cross the module boundary through narrow func seams (ContentResolver for slug resolution, ContentLookup for ID resolution) that project only comment-relevant facts. Core mounts the handlers explicitly — the surface spans four middleware groups plus the agent realm, which a single RegisterRoutes call cannot express — through structural CommentBrowserHandler/CommentAgentHandler interfaces in routes.go, so routes stay module-agnostic and paths never drift.

Migrations

Each module versions independently in its own schema_migrations_<module> table (see internal/database/modules.go), so modules install and upgrade without touching the core sequence. Module migrations must stay idempotent (CREATE TABLE IF NOT EXISTS): pre-module installs already carry tables extracted from the core sequence.

Documentation

Overview

Package comments is the official comment-system module: per-content discussion with moderation (pending/approved/rejected/spam).

Index

Constants

View Source
const (
	// Name is the registry key for this module.
	Name = "comments"

	// Version is the module version reported via Module.Version.
	Version = "0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

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

Module is the comments kernel module.

func New

func New(opts ...Option) *Module

New builds the module, adopting the composition root's wiring. Both realm handlers are built once here so routes serve the same instances.

func (*Module) AdminManifest

func (m *Module) AdminManifest() kernel.AdminExtensionManifest

AdminManifest declares this module's admin-shell extensions: the comments moderation navigation entry.

func (*Module) AgentHandler

func (m *Module) AgentHandler() *agent.CommentHandler

AgentHandler exposes the Bearer-realm handler for core mounting, alongside the browser handler for the same per-group reason.

func (*Module) BrowserHandler

func (m *Module) BrowserHandler() *api.CommentHandler

BrowserHandler exposes the JWT/CSRF-realm handler for core mounting. Core mounts it explicitly (rather than via RouteProvider) because the comment surface spans four middleware groups plus the agent realm, which a single RegisterRoutes call cannot express.

func (*Module) Init

func (m *Module) Init(_ kernel.Kernel) error

Init wires the module. The handlers are already built by New; Init only validates presence. Migration execution is core-driven (it needs the live *sql.DB, which modules never touch directly).

func (*Module) Migrations

func (m *Module) Migrations() fs.FS

Migrations returns the embedded migration filesystem, laid out per driver ({sqlite,postgresql,mysql}/NNN_name.{up,down}.sql). The core runner tracks each module in its own schema_migrations_<module> table.

func (*Module) Name

func (m *Module) Name() string

Name returns the registry key.

func (*Module) Optional

func (m *Module) Optional() []string

Optional lists soft dependencies. None.

func (*Module) Requires

func (m *Module) Requires() []string

Requires lists hard dependencies. Comments reference content items and users loosely (owner/content IDs without foreign-key enforcement), but the wrapper graph this module replaces declared users — keep the edge so the composition resolves identically.

func (*Module) Service

func (m *Module) Service() *commentdomain.Service

Service exposes the adopted domain service for composition-root wiring. It stays valid for the module's lifetime.

func (*Module) Shutdown

func (m *Module) Shutdown() error

Shutdown releases module resources. There are none beyond memory.

func (*Module) Version

func (m *Module) Version() string

Version returns the module version.

type Option

type Option func(*Module)

Option configures a Module. The composition root supplies every option; direct construction without options yields a standalone module that serves nothing (handlers built over nil dependencies must not be invoked).

func WithAgentContentLookup

func WithAgentContentLookup(lookup agent.ContentLookup) Option

WithAgentContentLookup attaches the content lookup for the agent handlers. Without one content-scoped endpoints fail at lookup time.

func WithAgentRoles

func WithAgentRoles(roles agent.RoleCapabilities) Option

WithAgentRoles attaches the role registry for the agent comment gate. It is a separate option (rather than sharing WithRoles) because the two api packages own their seams independently; core satisfies both with one adapter.

func WithContentResolver

func WithContentResolver(resolve api.ContentResolver) Option

WithContentResolver attaches the published-content lookup for the browser handlers. Without one content-scoped endpoints fail at lookup time.

func WithLogger

func WithLogger(logger kernel.Logger) Option

WithLogger attaches the module logger. Without one handler failures are dropped (discard sink).

func WithRoles

func WithRoles(roles api.RoleCapabilities) Option

WithRoles attaches the role registry for the browser comment gate. Without one every authenticated caller may post comments (the legacy behavior).

func WithService

func WithService(service *commentdomain.Service) Option

WithService adopts the comments domain service (composition root). The same instance backs the browser and agent handlers so validation, the AllowComments gate, and moderation transitions run identically in both realms.

Directories

Path Synopsis
Package admin owns this module's admin-shell manifest: the declarative UI the single admin SPA renders for comments.
Package admin owns this module's admin-shell manifest: the declarative UI the single admin SPA renders for comments.
api
Package store is the single-source comment repository: one implementation against *sql.DB plus a kernel Dialect, replacing the three per-driver copies.
Package store is the single-source comment repository: one implementation against *sql.DB plus a kernel Dialect, replacing the three per-driver copies.
Package testutil provides the kernel fixture module tests run against.
Package testutil provides the kernel fixture module tests run against.

Jump to

Keyboard shortcuts

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