handlers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package handlers registers HTTP handlers on the web server's mux.

S02 ships the full chi-routed surface plus error pages. Each future sprint adds its own routes via this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(mux *http.ServeMux, deps Deps) error

Register is preserved for the existing test suite that exercises the surface without bringing up the full server. Internally it wraps RegisterChi and mounts the chi router on mux.

func RegisterChi

func RegisterChi(r *chi.Mux, deps Deps) (*chi.Mux, middleware.PanicHandler, http.HandlerFunc, error)

RegisterChi wires every S02 route into r. Returns the chi.Router (for further wiring), a panic handler that the caller installs in the recover middleware, and a NotFound handler for the catch-all.

Types

type Deps

type Deps struct {
	Logger       *slog.Logger
	TemplatesFS  fs.FS
	StaticFS     fs.FS
	LogoSVG      string
	SessionStore session.Store
	// ReadyCheck is optionally invoked by /readyz. Returning a non-nil
	// error makes /readyz report 503. If nil, /readyz always reports ready.
	ReadyCheck func(context.Context) error
	// MetricsHandler, when non-nil, is mounted at /metrics. Caller is
	// responsible for any access control (e.g. HTTP Basic auth wrapping).
	MetricsHandler http.Handler
	// AuthMounter, when non-nil, is invoked inside the CSRF-protected
	// route group with the chi.Router so the auth handlers can register
	// signup/login/logout/reset/verify routes.
	AuthMounter func(chi.Router)
	// APIMounter, when non-nil, is invoked inside the CSRF-EXEMPT route
	// group so the API surface (PAT-authenticated, no browser-form
	// posts) can register its routes.
	APIMounter func(chi.Router)
	// AvatarMounter, when non-nil, registers /avatars/{username} on the
	// CSRF-exempt group (avatar GETs are safe and benefit from caching).
	AvatarMounter func(chi.Router)
	// RepoNewMounter, when non-nil, registers /new on the CSRF-protected
	// group. The handler enforces auth itself.
	RepoNewMounter func(chi.Router)
	// RepoHomeMounter, when non-nil, registers /{owner}/{repo} on the
	// CSRF-protected group. Two-segment match doesn't collide with the
	// /{username} catch-all.
	RepoHomeMounter func(chi.Router)
	// RepoLifecycleMounter, when non-nil, registers the danger-zone
	// routes (rename, transfer, archive, visibility, delete, restore,
	// transfer accept/decline/cancel, inbox). All routes are auth-
	// required; the handler enforces policy.Can per route.
	RepoLifecycleMounter func(chi.Router)
	// RepoCodeMounter, when non-nil, registers /tree/* /blob/* /raw/*
	// /find/* under the repo two-segment prefix. Public for read; the
	// handler runs the policy gate per request.
	RepoCodeMounter func(chi.Router)
	// RepoHistoryMounter registers /commits/{ref}, /commit/{sha},
	// /blame/{ref}/{path...}, /commits/{ref}.atom (S18).
	RepoHistoryMounter func(chi.Router)
	// RepoRefsMounter registers /branches, /tags, /compare/* (S20).
	RepoRefsMounter func(chi.Router)
	// RepoSettingsBranchesMounter registers /settings/branches +
	// /settings/default-branch (S20). Auth-required.
	RepoSettingsBranchesMounter func(chi.Router)
	// RepoSettingsGeneralMounter registers the General/Access tabs and
	// the deferred-tab placeholders (webhooks, keys, notifications,
	// tags) under /{owner}/{repo}/settings/* (S32). Auth-required.
	RepoSettingsGeneralMounter func(chi.Router)
	// RepoWebhooksMounter registers the per-repo webhook CRUD +
	// delivery views under /{owner}/{repo}/settings/webhooks/* (S33).
	// Auth-required.
	RepoWebhooksMounter func(chi.Router)
	// RepoIssuesMounter registers /{owner}/{repo}/issues, /labels, and
	// /milestones routes (S21). Reads are public (per-repo policy gate);
	// writes are auth-required.
	RepoIssuesMounter func(chi.Router)
	// RepoPullsMounter registers /{owner}/{repo}/pulls* routes (S22).
	// Same auth shape as issues — reads public, writes auth-required.
	RepoPullsMounter func(chi.Router)
	// RepoSocialMounter registers /{owner}/{repo}/{star,unstar,watch,
	// stargazers,watchers} (S26). Stargazer/watcher GETs are public
	// (subject to repo visibility); the action POSTs require auth.
	RepoSocialMounter func(chi.Router)
	// RepoForkMounter registers /{owner}/{repo}/{fork,sync,forks}
	// (S27). The forks list GET is public; fork + sync POSTs are
	// auth-required.
	RepoForkMounter func(chi.Router)
	// SearchMounter registers /search and /search/quick (S28).
	// Both are public — visibility scoping is done inside the
	// search package via policy.VisibilityPredicate.
	SearchMounter func(chi.Router)
	// NotifInboxMounter registers the per-viewer notification inbox
	// + thread-subscribe + mark-read routes (S29). RequireUser is
	// applied inside the wiring layer because every route in the
	// set is per-recipient.
	NotifInboxMounter func(chi.Router)
	// NotifPublicMounter registers the unauthenticated one-click
	// unsubscribe endpoint (S29). HMAC-signed URL = no session
	// needed, so the route lives in the public group alongside
	// /healthz / /static.
	NotifPublicMounter func(chi.Router)
	// OrgCreateMounter registers /organizations/new + POST
	// /organizations (S30). Wrapped in RequireUser at the wiring
	// layer.
	OrgCreateMounter func(chi.Router)
	// OrgRoutesMounter registers /{org}/people + invite + member
	// management. Reads (people page) are public; mutations are
	// owner-gated inside the handler. Must register BEFORE the
	// /{username} catch-all so the `people` segment matches.
	OrgRoutesMounter func(chi.Router)
	// OrgInvitationsMounter registers /invitations/{token} +
	// accept/decline. RequireUser at the wiring layer.
	OrgInvitationsMounter func(chi.Router)
	// AdminMounter, when non-nil, registers /admin/* routes (S34).
	// The mounter wraps the handler chain in RequireUser +
	// RequireSiteAdmin so non-admins receive 404, not 403.
	AdminMounter func(chi.Router)
	// GitHTTPMounter, when non-nil, registers the smart-HTTP git routes
	// (`*.git/info/refs`, `git-upload-pack`, `git-receive-pack`). MUST
	// land in a route group that bypasses CSRF, response compression,
	// and the global request timeout — git generates its own pack
	// format, uses HTTP Basic, and clones can run for many minutes.
	GitHTTPMounter func(chi.Router)
	// ProfileMounter, when non-nil, registers the /{username} catch-all
	// route. MUST run last in its group — chi matches in registration
	// order, and {username} swallows everything else.
	ProfileMounter func(chi.Router)
}

Deps holds the dependencies the handlers need. The web package owns the embedded filesystems and constructs Deps; this package stays decoupled from the embed.FS instances so it remains testable.

Directories

Path Synopsis
Package admin owns the /admin/* surface — the operator dashboard for users/orgs/repos/jobs/audit/system management.
Package admin owns the /admin/* surface — the operator dashboard for users/orgs/repos/jobs/audit/system management.
Package api owns shithub's PAT-authenticated HTTP API surface.
Package api owns shithub's PAT-authenticated HTTP API surface.
Package auth wires the email/password auth handlers (signup, login, logout, password reset, email verification) onto the chi router.
Package auth wires the email/password auth handlers (signup, login, logout, password reset, email verification) onto the chi router.
Package githttp wires the smart-HTTP git protocol routes: info/refs + git-upload-pack + git-receive-pack.
Package githttp wires the smart-HTTP git protocol routes: info/refs + git-upload-pack + git-receive-pack.
Package notifications wires the S29 notification web surface:
Package notifications wires the S29 notification web surface:
Package orgs wires the S30 organization web surface:
Package orgs wires the S30 organization web surface:
Package profile owns the read-only public profile handlers: /{username} and /avatars/{username}.
Package profile owns the read-only public profile handlers: /{username} and /avatars/{username}.
Package repo wires the HTTP handlers for repository creation and the (placeholder) repo home page.
Package repo wires the HTTP handlers for repository creation and the (placeholder) repo home page.
Package search wires the S28 web search surface.
Package search wires the S28 web search surface.

Jump to

Keyboard shortcuts

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