web

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Overview

Package web is the HTTP adapter: a localhost notes viewer (`nt web`). It is a read adapter over the same domain (note/links/mutate) the CLI, TUI, and MCP server use — so it shows exactly what they store. It is deliberately structured to make editing a future additive change: state lives on the Server struct, notes are addressed by stable id, and the render path is one reusable function.

Index

Constants

View Source
const DefaultPort = 4321

DefaultPort is the stable port `nt web` binds by default, so the URL stays the same across runs (bookmarkable). If it's already in use, Serve falls back to a free port rather than failing — the address only changes on an actual conflict.

Variables

This section is empty.

Functions

func Serve

func Serve(version, addr string, onReady func(url string)) error

Serve opens the store and serves the SPA on addr (e.g. "127.0.0.1:4321"). If the requested port is taken, it falls back to a free one (so the port is stable run-to-run but a conflict doesn't crash the command). onReady, if non-nil, is called with the final base URL once the listener is bound — used by the detached server (`nt web --detach`) to record its real address in the PID file even when the port fell back.

Types

type Backlink struct {
	Title  string `json:"title"` // note title, or "" for a task source
	URL    string `json:"url"`   // /n/<id> for a note source; "" for a task
	Text   string `json:"text"`  // the matching line (shown for task sources)
	IsNote bool   `json:"isNote"`
}

Backlink is one "Linked from" entry for the note page.

type Server

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

Server holds the shared state for the viewer. Writes (notes and tasks) are always enabled; every write route is guarded by the per-process CSRF token.

func NewServer

func NewServer(eng *mutate.Engine, version string) (*Server, error)

NewServer initialises the server and warms the read-model.

func (*Server) Handler added in v0.4.0

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

Handler returns the viewer's HTTP handler so another host can serve the UI without nt binding a TCP port — e.g. a Wails desktop shell wiring it into assetserver.Options.Handler. This is the seam that lets the exact same server-rendered UI run as a native app. Call StartWatch first if you want live-reload. Editing is always enabled (CSRF-guarded).

func (*Server) SetSPA added in v0.4.0

func (s *Server) SetSPA(_ bool)

SetSPA is a no-op retained for embedder compatibility; the SPA is always served.

func (*Server) StartWatch added in v0.4.0

func (s *Server) StartWatch()

StartWatch begins watching the store and pushing SSE live-reload events. Serve calls this itself; embedders call it when they want live-reload.

type TaskRef

type TaskRef struct {
	Text   string `json:"text"`
	Status string `json:"status"`
	Source string `json:"source"`
}

TaskRef is one task that links to the note (the task↔note moat).

Directories

Path Synopsis
Package apitypes defines the JSON wire contract for the web SPA's /api/* endpoints.
Package apitypes defines the JSON wire contract for the web SPA's /api/* endpoints.

Jump to

Keyboard shortcuts

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