server

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 34 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 server exposes the workspace to the browser front end.

It listens on the loopback interface only and requires a token that is generated per run and handed to the window in its URL, so nothing else on the machine can drive the agents through it.

Index

Constants

This section is empty.

Variables

View Source
var Version = "dev"

Version is reported by the health endpoint. main sets it at startup.

Functions

func Probe

func Probe(baseURL, token string) (*healthMsg, error)

Probe checks whether a recorded instance is alive and answering, and returns what it reports about itself.

An instance that answers but reports itself not ready is given a while: the caller's only other option is to declare the record stale and start a rival instance, which splits the agents in two and is much the worse mistake.

func RequestOpen

func RequestOpen(baseURL, token, path string) error

RequestOpen asks a running instance to open a project.

func RequestQuit

func RequestQuit(baseURL, token string) error

RequestQuit asks a running instance to shut down, and waits for it to have gone.

The instance answers as soon as it has accepted the request; stopping every agent and saving the layout comes after. Returning on the acceptance made `flockdeck -quit` say "stopped" while it was still going, and left the next launch racing it: a `flockdeck` typed straight afterwards would probe the instance on its way out, find it answering, and attach to a process that was about to exit -- ending up with a window onto nothing.

Types

type Server

type Server struct {

	// OnLastClientGone is called when the final window closes, so the
	// application can decide whether to shut down.
	OnLastClientGone func()
	// OnQuit is called when a shutdown is requested from the interface or by
	// another launch of the binary.
	OnQuit func()
	// OnRestart is called when the interface asks to come back up on a newly
	// downloaded version. It is separate from OnQuit because the shutdown has
	// to know whether to start the program again once it has replaced it.
	OnRestart func()
	// contains filtered or unexported fields
}

Server serves the front end and the live connections behind it.

func New

func New(ws *workspace.Workspace) (*Server, error)

New starts a server for the workspace on a free loopback port.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the listening address.

func (*Server) Attach

func (s *Server) Attach()

Attach reverses a detach, so closing the window quits again.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL is the address without the token, for the health and control endpoints a second launch uses.

func (*Server) ClientCount

func (s *Server) ClientCount() int

ClientCount reports how many windows are currently connected.

func (*Server) Close

func (s *Server) Close() error

Close shuts the server down.

func (*Server) Detach

func (s *Server) Detach()

Detach makes the application keep running after its last window closes, so the agents carry on and can be reattached to later.

func (*Server) Detached

func (s *Server) Detached() bool

Detached reports whether the application should outlive its windows.

func (*Server) RefreshGitNow

func (s *Server) RefreshGitNow()

RefreshGitNow asks the git loop to re-examine the checkouts straight away. It is safe to call from any goroutine and never blocks; a request made while one is already pending is folded into it.

func (*Server) SetUpdate

func (s *Server) SetUpdate(u *UpdateView)

SetUpdate records that a release has been staged and is ready to be applied by a restart, so the next snapshot tells the windows about it.

func (*Server) Token

func (s *Server) Token() string

Token returns the per-run token.

func (*Server) URL

func (s *Server) URL() string

URL is the address the window should open, including the token that authorises it.

func (*Server) Update

func (s *Server) Update() *UpdateView

Update returns the staged release, or nil when there is none.

func (*Server) Wake

func (s *Server) Wake()

Wake tells the server that workspace state changed and clients should be updated. It is safe to call from any goroutine and never blocks.

type UpdateView

type UpdateView struct {
	Version string `json:"version"`
	Notes   string `json:"notes,omitempty"`
	URL     string `json:"url,omitempty"`
}

UpdateView is a downloaded release as the interface shows it.

Jump to

Keyboard shortcuts

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