server

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 41 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 ErrNotReady = errors.New("the instance is not ready")

ErrNotReady marks the one failure worth waiting out: flockdeck is listening on that address, it just cannot answer for its workspace this moment.

It is exported for the launch deciding what an error from Probe means. Every other failure says nothing is there; this one says an instance is there and busy, and taking it for a stale record would start a rival set of agents beside the ones it is busy with.

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.

func RequestRemoteReload added in v0.2.0

func RequestRemoteReload(baseURL, token string) error

RequestRemoteReload asks a running instance to reread the enrolment.

Types

type RemoteAccess added in v0.2.0

type RemoteAccess interface {
	Status() (remote.Status, bool)
	Client() (*remote.Client, error)
	Reload() error
	Enable(ctx context.Context, req remote.EnableRequest) (replaced bool, err error)
	Disable(ctx context.Context, force bool) (untold error, err error)
	Reconnect() error
}

RemoteAccess is what the server needs of remote access: to say how the tunnel is, to reach the relay on the window's behalf, to be told to reread the enrolment, and to turn it on and off and try the relay again from the dialog as `flockdeck remote` does from a terminal.

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()
	// OnDetach is called when the instance becomes detached -- from a window,
	// or by -detach at start -- once each time it goes from attached to
	// detached, and never on the workspace goroutine. It is how the application
	// lets go of what tied it to the way it was started: on Windows, the console
	// a -no-window run was launched from, whose closing would otherwise end it.
	OnDetach 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. OnDetach is told once each time the instance goes from attached to detached, on a goroutine of its own: a window's Detach arrives on the workspace goroutine, and whatever the hook does is not that goroutine's to wait for.

func (*Server) Detached

func (s *Server) Detached() bool

Detached reports whether the application should outlive its windows.

func (*Server) LocalClientCount added in v0.2.0

func (s *Server) LocalClientCount() int

LocalClientCount reports how many windows on this machine are connected — every window, that is, but the ones reached through the relay.

It is what decides whether the application is still being looked at. A remote window is somebody elsewhere, and whether it is open says nothing about the window on the desk: closing that one still quits an instance that was not detached, and a remote window closing never quits anything. The way to leave the agents running for a remote window to find is the same as it always was — detach.

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) RemoteHandler added in v0.2.0

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

RemoteHandler is the window's own set of handlers, with every request marked as having arrived through the tunnel.

func (*Server) ServeRemote added in v0.2.0

func (s *Server) ServeRemote(l net.Listener) error

ServeRemote answers the connections arriving on l, which is one tunnel's worth of them, until l is closed or the server is.

Closing l ends the serving but not a WebSocket already handed over: those have left net/http's hands, and it is closing the tunnel under them — which is what the caller does when it closes l — that ends them.

func (*Server) SetRemote added in v0.2.0

func (s *Server) SetRemote(r RemoteAccess)

SetRemote hands the server its remote access, which may be nil.

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, and has the windows told.

Nothing else would tell them. A snapshot goes out when something changes, and a release is staged in the background, hours into a run, most likely while the agents sit waiting and nobody is touching the window -- which is then not told until something unrelated happens.

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