server

package
v0.0.0-...-3205eea Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSanitizer

func NewSanitizer() *bluemonday.Policy

NewSanitizer creates the bluemonday HTML sanitizer with the standard policy. Used by both the main server and the WASM demo.

func PrintModeMiddleware

func PrintModeMiddleware(handler http.Handler) http.Handler

PrintModeMiddleware checks for the ?print query parameter and stores it in context.

func RegisterSpecialPages

func RegisterSpecialPages(articles service.ArticleService, users service.UserService, t *templater.Templater, baseURL string) *special.Registry

RegisterSpecialPages creates and populates a special page registry. Used by both the main server and the WASM demo.

func SlogLoggingMiddleware

func SlogLoggingMiddleware(next http.Handler) http.Handler

SlogLoggingMiddleware logs HTTP requests using slog

Types

type App

type App struct {
	*templater.Templater
	Articles      service.ArticleService
	Users         service.UserService
	Sessions      service.SessionService
	Rendering     service.RenderingService
	Preferences   service.PreferenceService
	SpecialPages  *special.Registry
	Config        *wiki.Config
	RuntimeConfig *wiki.RuntimeConfig
	ContentInfo   *ContentInfo
	DB            *sql.DB
}

App holds all application dependencies and services.

func Setup

func Setup(contentFS fs.FS, contentInfo *ContentInfo) (*App, *renderqueue.Queue)

Setup initializes the application and returns the App instance along with the render queue (which must be shut down when the server stops).

func (*App) ArticleDispatcher

func (a *App) ArticleDispatcher(rw http.ResponseWriter, req *http.Request)

ArticleDispatcher routes article requests based on query parameters. URL scheme:

  • /wiki/{article} - view article (current revision)
  • /wiki/{article}?revision=N - view specific revision
  • /wiki/{article}?edit - edit current revision
  • /wiki/{article}?edit&revision=N - edit/restore revision N
  • /wiki/{article}?history - view revision history
  • /wiki/{article}?diff&old=N&new=M - diff between revisions
  • /wiki/{article}?diff&old=N - diff from N to current
  • /wiki/{article}?diff&new=M - diff from previous to M
  • /wiki/{article}?diff - diff between two most recent revisions
  • /wiki/{article}?rerender - force re-render current revision
  • /wiki/{article}?rerender&revision=N - force re-render revision N

func (*App) ArticleHandler

func (a *App) ArticleHandler(rw http.ResponseWriter, req *http.Request)

func (*App) ArticleMarkdownHandler

func (a *App) ArticleMarkdownHandler(rw http.ResponseWriter, req *http.Request)

func (*App) BackfillLinksHandler

func (a *App) BackfillLinksHandler(rw http.ResponseWriter, req *http.Request)

BackfillLinksHandler triggers a full link graph rebuild.

func (*App) ErrorHandler

func (a *App) ErrorHandler(responseCode int, rw http.ResponseWriter, req *http.Request, errors ...error)

func (*App) HomeHandler

func (a *App) HomeHandler(rw http.ResponseWriter, req *http.Request)

func (*App) LoginHandler

func (a *App) LoginHandler(rw http.ResponseWriter, req *http.Request)

func (*App) LoginPostHandler

func (a *App) LoginPostHandler(rw http.ResponseWriter, req *http.Request)

func (*App) LogoutPostHandler

func (a *App) LogoutPostHandler(rw http.ResponseWriter, req *http.Request)

func (*App) ManageContentHandler

func (a *App) ManageContentHandler(rw http.ResponseWriter, req *http.Request)

ManageContentHandler displays the content files tree for admin inspection.

func (*App) ManageSettingsHandler

func (a *App) ManageSettingsHandler(rw http.ResponseWriter, req *http.Request)

ManageSettingsHandler displays the runtime settings form.

func (*App) ManageSettingsPostHandler

func (a *App) ManageSettingsPostHandler(rw http.ResponseWriter, req *http.Request)

ManageSettingsPostHandler handles POST requests to update runtime settings.

func (*App) ManageToolsHandler

func (a *App) ManageToolsHandler(rw http.ResponseWriter, req *http.Request)

ManageToolsHandler displays the admin tools page.

func (*App) ManageUserRoleHandler

func (a *App) ManageUserRoleHandler(rw http.ResponseWriter, req *http.Request)

ManageUserRoleHandler handles POST requests to change a user's role.

func (*App) ManageUsersHandler

func (a *App) ManageUsersHandler(rw http.ResponseWriter, req *http.Request)

ManageUsersHandler lists all users for admin management.

func (*App) NamespaceHandler

func (a *App) NamespaceHandler(rw http.ResponseWriter, req *http.Request)

NamespaceHandler routes requests for namespaced URLs (anything with a colon). Recognized namespaces: Special (dynamic pages), Periwiki (embedded help).

func (*App) RegisterHandler

func (a *App) RegisterHandler(rw http.ResponseWriter, req *http.Request)

func (*App) RegisterPostHandler

func (a *App) RegisterPostHandler(rw http.ResponseWriter, req *http.Request)

func (*App) RegisterRoutes

func (a *App) RegisterRoutes(router *mux.Router, contentFS fs.FS)

RegisterRoutes adds all application routes to the given router. Both the main server and the WASM demo call this to avoid duplication.

func (*App) RequireAdmin

func (a *App) RequireAdmin(rw http.ResponseWriter, req *http.Request) *wiki.User

RequireAdmin returns the user if they are an admin, or shows an appropriate error and returns nil. Anonymous users are redirected to login; authenticated non-admins get a 403 page.

func (*App) RequireAuth

func (a *App) RequireAuth(rw http.ResponseWriter, req *http.Request) *wiki.User

RequireAuth returns the authenticated user, or redirects to login and returns nil.

func (*App) ResetMainPageHandler

func (a *App) ResetMainPageHandler(rw http.ResponseWriter, req *http.Request)

ResetMainPageHandler resets the Main_Page article to the embedded default content.

func (*App) SessionMiddleware

func (a *App) SessionMiddleware(handler http.Handler) http.Handler

type ContentFileEntry

type ContentFileEntry struct {
	Path   string // e.g. "templates/layouts/index.html"
	Source string // "embedded" or "disk"
}

ContentFileEntry describes a single file in the content filesystem.

type ContentInfo

type ContentInfo struct {
	Files       []ContentFileEntry
	BuildCommit string
	SourceURL   string // URL to the source at this commit
}

ContentInfo holds metadata about embedded content files for the admin UI.

type ExistenceState

type ExistenceState struct {
	Embedded     *embedded.EmbeddedArticles
	SpecialPages *special.Registry
	// contains filtered or unexported fields
}

ExistenceState holds the mutable dependencies for the existence checker. Embedded and SpecialPages are set after initial creation.

func NewExistenceChecker

func NewExistenceChecker(db repository.ArticleRepository) (func(string) bool, *ExistenceState)

NewExistenceChecker creates the wikilink existence checker function. The returned ExistenceState must have its Embedded and SpecialPages fields set after creation (they are nil initially due to circular dependencies).

Jump to

Keyboard shortcuts

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