server

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const ShutdownBudget = 3 * time.Second

ShutdownBudget is how long graceful shutdown may take. main.go uses it for its shutdown context, and sseWriteDeadline is defined strictly under it, so the two cannot drift apart into a shutdown that always force-closes.

Variables

This section is empty.

Functions

func HostValidationMiddleware

func HostValidationMiddleware(next http.Handler, port int) http.Handler

func SeqPath added in v1.2.0

func SeqPath(store *versions.Store) string

SeqPath is where the live-sync sequence high-water mark lives, beside the backups in a private 0700 directory the server refuses to serve.

func ValidateHost

func ValidateHost(r *http.Request, port int) bool

func ValidatePath

func ValidatePath(relPath string, homeDir string) (string, error)

Types

type LiveSync added in v1.2.0

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

LiveSync bundles the process-wide live-sync machinery: the pub/sub hub, the file watcher, and the coordinator that keeps their membership in step. One LiveSync is shared by every per-tree site. It keys all state by absolute file path, and absolute paths are unique across the single home directory, so sharing one instance never collides between sites.

func NewLiveSync added in v1.2.0

func NewLiveSync(seqPath string, logger *logging.Logger) *LiveSync

NewLiveSync builds the shared live-sync runtime. seqPath is the persisted sequence high-water mark, which lives beside the backups in a private 0700 directory the server refuses to serve.

func (*LiveSync) Shutdown added in v1.2.0

func (ls *LiveSync) Shutdown()

Shutdown stops the watcher and closes every SSE stream across all sites. Call it once at process exit, before shutting down the per-site HTTP servers, so graceful shutdown does not wait on open SSE connections.

type Server

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

func New

func New(ln net.Listener, sessions *session.Manager, logger *logging.Logger, store *versions.Store) *Server

New builds a server that owns its own live-sync runtime and tears it down on Shutdown/Close. Used by tests and any single-server caller.

func NewWithLiveSync added in v1.2.0

func NewWithLiveSync(ln net.Listener, sessions *session.Manager, logger *logging.Logger, store *versions.Store, ls *LiveSync) *Server

NewWithLiveSync builds a server that shares an injected live-sync runtime with its sibling sites. The runtime is owned by the process, not by any one server, so Shutdown/Close leave it running; the process shuts it down once.

func (*Server) Close

func (s *Server) Close() error

func (*Server) SetConfirm added in v1.2.0

func (s *Server) SetConfirm(fn func(title, message string) (platform.ConfirmChoice, error))

SetConfirm replaces the permission prompt. Production uses the native dialog; tests inject a deterministic decision so no real dialog is ever shown.

func (*Server) SetInternalDir added in v1.2.0

func (s *Server) SetInternalDir(dir string)

SetInternalDir marks a directory the server must never serve, whatever the read roots say. htmlclay's own config tree holds its log and settings, and a grant that happens to cover that directory must not turn into a read path. Denying on the serve path is structural; a grant-time guard can only ever cover the grants it happens to see.

func (*Server) SetSiteLabel added in v1.2.0

func (s *Server) SetSiteLabel(label string)

SetSiteLabel names this site in the permission dialog so the user knows which page is asking. Optional; the broker falls back to a generic label.

func (*Server) SetTrustFolder added in v1.2.0

func (s *Server) SetTrustFolder(fn func(dir string) error)

SetTrustFolder wires the durable half of the permission dialog's "Trust this folder" choice. Optional: with no hook the choice still installs the session read root, so the page works and the folder simply asks again next launch.

func (*Server) Shutdown

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

Shutdown releases parked permission requests and closes every SSE stream before handing off to http.Server.Shutdown. Both otherwise hold graceful shutdown open until its timeout and are then force-closed. A server that shares an injected live-sync runtime leaves it running (the process shuts the shared runtime down once, before the per-site HTTP servers).

func (*Server) Start

func (s *Server) Start() error

Jump to

Keyboard shortcuts

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