Help us shape the future of Go! Take the 2026 Go Developer Survey

devserver

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package devserver serves immutable development builds and reconnecting updates.

Index

Constants

View Source
const (
	Schema = "karty.dev@1"
)

Variables

View Source
var ErrSnapshot = errors.New("invalid or oversized development build")

Functions

func Run

func Run(ctx context.Context, server *Server, options RunOptions) error

Run serializes builds and snapshots while keeping the HTTP server responsive. Failed and obsolete builds never replace the last successful generation.

Types

type Generation

type Generation struct {
	Revision        uint64     `json:"revision"`
	ID              string     `json:"id"`
	RuntimeIdentity string     `json:"runtimeIdentity"`
	BaseURL         string     `json:"baseURL"` //nolint:tagliatelle // The versioned tooling schema spells URL as an initialism.
	Levels          []Level    `json:"levels"`
	UI              UIResource `json:"ui"`
}

type Level

type Level struct {
	Name            string `json:"name"`
	Kind            string `json:"kind"`
	ContentSHA256   string `json:"contentSha256"`
	Size            uint64 `json:"size"`
	EnvelopeVersion uint16 `json:"envelopeVersion"`
	Artifact        string `json:"artifact"`
}

type RunOptions

type RunOptions struct {
	Directory    string
	Build        func(context.Context, func(string)) error
	PollInterval time.Duration
	Debounce     time.Duration
	Log          func(string)
	// WatchRoots supplies explicitly declared development package roots. Each
	// is watched independently without permitting project symlinks to escape.
	WatchRoots func(context.Context) (map[string]string, error)
}

RunOptions keeps the watcher independent of compilers and the build service. Build must return only after cancellation cleanup has completed.

type Server

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

func New

func New() (*Server, error)

func NewServer

func NewServer() (*Server, error)

func (*Server) Close

func (server *Server) Close()

func (*Server) Publish

func (server *Server) Publish(snapshot *Snapshot)

func (*Server) ServeHTTP

func (server *Server) ServeHTTP(output http.ResponseWriter, request *http.Request)

func (*Server) SetStatus

func (server *Server) SetStatus(state, message string)

type Snapshot

type Snapshot struct {
	Generation Generation
	// contains filtered or unexported fields
}

func Capture

func Capture(ctx context.Context, directory string, revision uint64) (*Snapshot, error)

Capture owns all served bytes before publication. No requests read dist again.

type Status

type Status struct {
	Schema     string      `json:"schema"`
	Session    string      `json:"session"`
	State      string      `json:"state"`
	Message    string      `json:"message"`
	Generation *Generation `json:"generation"`
}

type UIResource

type UIResource struct {
	Artifact      string `json:"artifact"`
	ContentSHA256 string `json:"contentSha256"`
	Size          uint64 `json:"size"`
}

type Watcher

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

Watcher detects content changes, including additions and deletion. Metadata avoids rereading unchanged large assets on each poll. Hashes expire so edits that preserve inode/size/mtime are still detected within the verification age. os.Root confines every read even if a symlink changes during a scan.

func NewWatcher

func NewWatcher(directory string) (*Watcher, error)

func (*Watcher) Close

func (watcher *Watcher) Close() error

func (*Watcher) Scan

func (watcher *Watcher) Scan(ctx context.Context) (string, error)

Jump to

Keyboard shortcuts

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