web

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: BSD-3-Clause Imports: 39 Imported by: 0 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.

Documentation

Overview

Package web holds the HTTP server, the routes, the middleware, the handlers and the server-sent event streams. It never imports internal/store.

Index

Constants

View Source
const CallSocketPath = "/calls/{id}/ws"

CallSocketPath is the pattern of the path of the signalling socket of the call in a direct conversation, GET /calls/{id}/ws with the ID of the conversation (SPEC §7.18).

Variables

This section is empty.

Functions

func ClientIPFunc added in v1.1.0

func ClientIPFunc(trustProxy bool) func(*http.Request) string

ClientIPFunc returns the function that finds the address of the client of a request, for the login limiter: the connection's address, or with trustProxy the last address of X-Forwarded-For (see clientIP). It is what the API is given as api.Options.ClientIP.

func NoteUser added in v1.1.0

func NoteUser(r *http.Request, userID uint64)

NoteUser records on the request that user userID made it, so that the request log names the user. It is the hook the API calls once a bearer token is accepted (api.Options.NoteUser). A request that did not go through the server's handler is not changed.

Types

type HealthChecker added in v1.1.0

type HealthChecker interface {
	// Check returns nil when the database answers within ctx.
	Check(ctx context.Context) error
}

HealthChecker tells whether the server can do its work. app.Health is the one the binary uses.

type Server

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

Server is the HTTP server of Clowder: the routes, the middleware and the handlers. Make it with New.

func New

func New(cfg config.Config, logger *slog.Logger, svc Services) (*Server, error)

New makes the server from its dependencies. Run starts it. It fails when the embedded static files cannot be read and hashed.

func (*Server) Handler

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

Handler returns the whole handler stack: the security headers, request logging, panic recovery, cross-origin protection and the routes.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run listens on the configured address and serves until ctx is done. Then it stops accepting requests and waits for the running ones for 10 seconds (SPEC §8). It returns nil after a clean shutdown.

type Services

type Services struct {
	// Accounts is the service of login, sessions, invitations and users.
	Accounts *app.Accounts
	// Rooms is the service of rooms and their memberships.
	Rooms *app.Rooms
	// Audit is the service that reads the audit log.
	Audit *app.Audit
	// Posts is the service of posts, their tags and their feeds.
	Posts *app.Posts
	// Board is the service of the Kanban boards. The streams read it to find
	// the posts whose tasks a change of the columns concerns.
	Board *app.Board
	// Search is the service of search.
	Search *app.Search
	// Notifications is the service of the notifications of a user: their
	// unread count in the sidebar and their page.
	Notifications *app.Notifications
	// Messages is the service of private conversations and messages: their
	// pages, their streams and the unread count in the sidebar.
	Messages *app.Messages
	// Prefs is the service of the notification preferences of a user in a
	// room or a conversation, and of the notices their streams carry.
	Prefs *app.Prefs
	// Presence tells who is online and is told when a stream opens or closes
	// (SPEC §7.15). Nil counts nobody.
	Presence *app.Presence
	// SSHKeys is the service of the SSH keys of a user and of what the
	// settings page shows of the SSH server (SPEC §7.16).
	SSHKeys *app.SSHKeys
	// Calls is the service of the one-to-one calls (SPEC §7.18). Nil serves no
	// call socket.
	Calls *app.Calls
	// Media is the media server of the calls, which runs the signalling
	// socket. Nil when calls are off.
	Media *calls.Server
	// Health answers the health check, GET /healthz (SPEC D40). Nil makes
	// the check answer 503.
	Health HealthChecker
	// API is the REST API (SPEC D42). Its routes are mounted on the same mux
	// under /api/v1/ and never read the session cookie. Nil serves no API:
	// every /api/ path is then the page-not-found error page.
	API *api.Server
	// Hub delivers the live events of the services to the streams of the
	// pages (SPEC §8). The services must publish to the same hub. Nil makes a
	// hub that nothing publishes to.
	Hub *live.Hub
	// Connections counts the live connections of each user in this process,
	// for the limit of SPEC D62; it must be the one of the API. Nil limits
	// nothing.
	Connections *app.Connections
	// Metrics receives the requests that ended and the open streams (SPEC
	// D60). Nil reports nothing.
	Metrics *metrics.Set
}

Services are the services the handlers call. Later steps add a field for each service they build.

Directories

Path Synopsis
Package static holds the files the server sends as they are: the Datastar client, the stylesheet and the scripts.
Package static holds the files the server sends as they are: the Datastar client, the stylesheet and the scripts.
Package views holds the templ components and pages.
Package views holds the templ components and pages.

Jump to

Keyboard shortcuts

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