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

workspace

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package workspace provides a filesystem confined to a single root directory. Every operation resolves the caller-supplied path against the root and refuses any path that would escape it, so it is safe to drive from an HTTP API. It backs the Dexaflow Lite web editor (ADR 0025); it is never the Production path.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsafePath = errors.New("unsafe path")

ErrUnsafePath is returned (wrapped) when a requested path is absolute or would escape the workspace root. Callers can map it to a client error with errors.Is.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Path  string `json:"path"`
	Name  string `json:"name"`
	IsDir bool   `json:"is_dir"`
	Size  int64  `json:"size"`
}

Entry is one node in the workspace tree. Path is relative to the root and always slash-separated.

type FS

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

FS is a filesystem confined to a single root directory. The zero value is not usable; construct one with New.

func New

func New(dir string) (*FS, error)

New returns an FS rooted at dir. dir must be an existing directory; New resolves it to an absolute, symlink-free path so later confinement checks are exact.

func (*FS) Create

func (f *FS) Create(rel string, dir bool) error

Create makes an empty file at rel, or a directory when dir is true, including any missing parents.

func (*FS) Delete

func (f *FS) Delete(rel string) error

Delete removes the file or directory (recursively) at rel.

func (*FS) Move

func (f *FS) Move(from, to string) error

Move renames or relocates a file or directory inside the workspace. It auto-creates any missing parent directories on the destination side, and refuses to clobber an existing destination — the IDE surface (drag-drop / rename) asks the user to pick a fresh name on a collision.

func (*FS) Read

func (f *FS) Read(rel string) ([]byte, error)

Read returns the contents of the file at rel.

func (*FS) Root

func (f *FS) Root() string

Root returns the absolute, resolved root directory.

func (*FS) Tree

func (f *FS) Tree() ([]Entry, error)

Tree walks the workspace and returns every file and directory (except noise directories), with paths relative to the root, sorted for a stable display.

func (*FS) Write

func (f *FS) Write(rel string, data []byte) error

Write saves data to the file at rel, creating any missing parent directories.

Jump to

Keyboard shortcuts

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