Documentation
¶
Overview ¶
Package server provides an HTTP API for the iterion editor. It wraps the parser, compiler, and unparser to provide endpoints for parsing .iter files, validating workflows, and generating .iter text.
Index ¶
Constants ¶
const ( EventFileCreated = "file_created" EventFileModified = "file_modified" EventFileDeleted = "file_deleted" )
Variables ¶
This section is empty.
Functions ¶
func SetWebSocketOriginCheck ¶
SetWebSocketOriginCheck registers the origin allowlist function used by the WebSocket upgrader. Called by Server during routes() setup.
Types ¶
type Config ¶
type Config struct {
Port int // HTTP port (default 4891)
Bind string // bind address (default "127.0.0.1"; use "0.0.0.0" only with explicit user opt-in)
ExamplesDir string // path to examples directory
WorkDir string // root directory for file operations
StoreDir string // run store directory (default: <WorkDir>/.iterion)
OpenBrowser bool // open browser on start
}
Config holds the server configuration.
type DiagnosticDTO ¶
type DiagnosticDTO struct {
Code string `json:"code,omitempty"`
Severity string `json:"severity"`
Message string `json:"message"`
NodeID string `json:"node_id,omitempty"`
EdgeID string `json:"edge_id,omitempty"`
Hint string `json:"hint,omitempty"`
}
DiagnosticDTO is the wire-safe shape of an ir.Diagnostic. It carries the structured fields (code, severity, attribution, hint) so the editor can render inline badges without resorting to string-matching the message.
type FileEvent ¶
type FileEvent struct {
Type string `json:"type"` // file_created, file_modified, file_deleted
Path string `json:"path"` // relative to WorkDir
}
FileEvent is the JSON message sent to WebSocket clients when a file changes.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active WebSocket clients and broadcasts messages to them.
func (*Hub) Broadcast ¶
Broadcast marshals a FileEvent to JSON and sends it to all connected clients.
func (*Hub) HandleWebSocket ¶
func (h *Hub) HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket upgrades an HTTP connection to WebSocket and registers the client.
Shutdown safety: if the hub has already been Stop()'d (h.done closed), the Run() goroutine has exited and `h.register` has no receiver — a naive `h.register <- c` here would block the HTTP handler goroutine forever and leak its conn. We short-circuit on that and refuse the upgrade. We also guard the register send itself with a select-on-done in case Stop fires concurrently with this handler.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the editor HTTP server.
func (*Server) ListenAndServe ¶
ListenAndServe starts the HTTP server.
func (*Server) Shutdown ¶
Shutdown gracefully shuts down the server.
Order matters: HTTP-level shutdown (Server.Shutdown) drains in-flight requests, while the run console service drains in-process workflow goroutines. We do the workflow drain first so any cancel events reach the on-disk store before the file watcher stops broadcasting and clients drop. The drain ctx is the caller-supplied shutdown deadline.
Drain (rather than Stop) is intentional: it flips each in-flight run to failed_resumable and emits EventRunInterrupted so the next boot can offer one-click resume and clients can distinguish shutdown-induced termination from user-initiated cancel.
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
Watcher watches WorkDir for .iter file changes and pushes events to a Hub.
func NewWatcher ¶
NewWatcher creates a new file watcher for the given directory.
func (*Watcher) IgnorePath ¶
IgnorePath marks a path to be ignored for the next ignoreWindow.