daemon

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package daemon holds a datavase session for a terminal that comes and goes.

It does not know what it is serving. A Session is three methods — set a screen, run, stop — which is all a terminal interface needs to expose and deliberately less than tview or internal/ui. That keeps this package testable against a stand-in, and keeps the interface free of any notion that it might be running headless.

It does not know about sockets either: Serve takes an io.ReadWriteCloser, so net.Pipe exercises the whole exchange.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRunning = errors.New("a dv server is already listening")

ErrAlreadyRunning reports that something answered on the socket already.

Functions

func APISocketPath

func APISocketPath() (string, error)

APISocketPath is where the observation socket lives.

A second socket rather than a second message on the first one: the client protocol is private, binary and high-frequency, and this is public, textual and rare. One socket carrying both would make each worse, and only this one may have several readers at a time.

func Dial

func Dial(path string) (net.Conn, error)

Dial connects to a running server.

func Listen

func Listen(path string) (net.Listener, error)

Listen takes the socket, replacing one that nothing answers on.

func LogPath

func LogPath() (string, error)

LogPath is where a spawned server writes what it could not say to anyone.

A server that dies while starting has no client to tell, and without this the failure is invisible.

func ServeAPI

func ServeAPI(ln net.Listener, src snapshot.Source)

ServeAPI answers snapshot requests until the listener closes.

One response per connection: there is one question, and a connection that asked it has nothing more to say. Readers are unlimited because none of them can change anything.

func SocketPath

func SocketPath() (string, error)

SocketPath is where a client looks for a server.

Beside the schema cache and the query history rather than beside the configuration file: this is runtime state, and it means nothing once the process behind it is gone.

Types

type Options

type Options struct {
	// Version is what a client must match exactly.
	Version string

	// BuildFingerprint is version.BuildFingerprint(): empty outside a
	// development build. It is compared only when both this and the client's
	// Hello.BuildFingerprint are non-empty, so a release server — which never
	// sets this — is never refused over it.
	BuildFingerprint string

	// Start builds the session the first client asked for, returning it and
	// anything the user should be told about how it was built — a schema
	// cache that would not open, a worktree that no longer exists. Those
	// would otherwise land in a log nobody reads.
	//
	// The context bounds building only, not the session that comes out of
	// it: whatever Start opens must outlive the call and is owned by the
	// returned Session from then on.
	Start func(context.Context, proto.Hello) (Session, []string, error)
}

type Server

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

Server holds one session and at most one client.

func New

func New(opts Options) *Server

func (*Server) Accept

func (s *Server) Accept(ln net.Listener)

Accept serves clients until the listener closes.

func (*Server) Detach

func (s *Server) Detach()

Detach drops the current client and keeps the session.

func (*Server) Info

func (s *Server) Info(dv string, started, now time.Time) snapshot.Server

Info is the tier of a snapshot that comes from this process. It cannot fail, which is what lets dv status answer whatever the session is doing.

func (*Server) Serve

func (s *Server) Serve(rwc io.ReadWriteCloser)

Serve runs one client to completion and returns when it goes away.

func (*Server) Stop

func (s *Server) Stop()

Stop ends the session. Wait returns once it has.

func (*Server) Wait

func (s *Server) Wait() error

Wait blocks until the session ends and returns why.

type Session

type Session interface {
	SetScreen(tcell.Screen)
	Run() error
	Stop()
}

Session is what is being held. *ui.App satisfies it as it stands.

type State

type State struct {
	DataSource string
	Busy       bool
}

State is what a second client needs to know before it may take the session somewhere else.

type Stateful

type Stateful interface {
	State(context.Context) (State, error)
}

Stateful is a Session that can answer from another goroutine. A Session that does not implement it, or that does not answer in time, is treated as busy: refusing is the smaller mistake.

type Switcher

type Switcher interface {
	SwitchTo(name string)
}

Switcher is a Session that can be moved to another datasource.

Jump to

Keyboard shortcuts

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