copyover

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumeReconnectToken

func ConsumeReconnectToken(token string) (int, bool)

ConsumeReconnectToken validates and consumes a token, returning the associated userId. Returns 0, false if the token is unknown or expired.

func Execute

func Execute(binaryPath string, extraArgs []string) error

Execute serializes all registered contributors into a pipe, launches the new process image with the pipe fd passed via --copyover-fd, then exits. extraArgs are forwarded as-is to the child process. Returns an error on platforms where copyover is not supported.

func IssueReconnectToken

func IssueReconnectToken(userId int) (string, error)

IssueReconnectToken creates a one-time reconnect token for the given userId and returns it. The token expires after 2 minutes.

func Register

func Register(c Contributor)

Register adds a contributor to the global registry. Must be called before copyover is triggered.

func ResetRegistry

func ResetRegistry()

ResetRegistry clears all registered contributors. Intended for use in tests.

func Restore

func Restore(fd int) error

Restore reads state from the given file descriptor and calls CopyoverRestore on all registered contributors.

func Save

func Save(w io.Writer) error

Save serializes all registered contributors into w.

Types

type Contributor

type Contributor interface {
	// CopyoverName returns a stable, unique key for this contributor.
	CopyoverName() string
	// CopyoverSave serializes state into the provided encoder.
	CopyoverSave(enc *Encoder) error
	// CopyoverRestore deserializes state from the provided decoder.
	CopyoverRestore(dec *Decoder) error
}

Contributor is implemented by any subsystem that needs to save/restore state across a copyover.

func FuncContributor

func FuncContributor(name string, save func(*Encoder) error, restore func(*Decoder) error) Contributor

FuncContributor returns a Contributor implemented by the provided functions. Intended for use in tests.

func TokenContributor

func TokenContributor() Contributor

TokenContributor returns the Contributor that persists reconnect tokens across a copyover. Register it in main alongside the other contributors.

type Decoder

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

Decoder reads named sections from a stream.

func (*Decoder) ReadSection

func (d *Decoder) ReadSection(name string, v any) error

ReadSection deserializes the named section into v.

type Encoder

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

Encoder writes named sections into a stream.

func (*Encoder) WriteSection

func (e *Encoder) WriteSection(name string, v any) error

WriteSection serializes v as JSON and writes it as a named section.

Jump to

Keyboard shortcuts

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