workspaceapi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileIsNotRegular is returned when file type was not expected to be a directory.
	ErrFileIsNotRegular = errors.New("file type is not regular")

	// ErrFileIsNotWritable is returned when file is opened in read-only.
	ErrFileIsNotWritable = errors.New("file is not writable")

	// ErrFileAlreadyOpen is returned when a file is not expected to be opened already.
	ErrFileAlreadyOpen = errors.New("file open by another process or previous process was closed abruptly")

	// ErrStaleData is returned when a file was modified by some other application.
	ErrStaleData = errors.New("file was modified by another process since reading it")
)

Functions

func ExpandPath

func ExpandPath(
	path string, getUser func() (*user.User, error),
	cwdFn func() (string, error),
) (string, error)

ExpandPath finds the absolute path of a relative path and expands the home shortcut (~) if any. If path is already absolute then this function returns the path unchanged.

func ExpandPathWithURI

func ExpandPathWithURI(
	path string, uri URI,
) (string, error)

ExpandPathWithURI finds the absolute path of a relative path. It uses the given URI to resolve user and cwd so ~ is an alias for a path relative to the base of the URI. See ExpandPath for more details.

func HasPrefix

func HasPrefix(uri, prefix URI) bool

HasPrefix returns tests whether uri begins with prefix.

func RelPath

func RelPath(base, target URI) string

RelPath returns target's path as a relative path of base, or if that's not possible, it will return target's Path without change.

Types

type Cmd

type Cmd struct {
	Path    string
	Dir     string
	Args    []string
	Env     []string
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
	Watcher ProcessWatcher

	// SysProcAttr is ignored if passed from a extension.
	SysProcAttr *syscall.SysProcAttr
}

Cmd represents an external command being prepared to run. See exec.Cmd for more details. Stdin, Stderr and Stdout, if set, will have their corresponding

type Executor

type Executor interface {
	// Start starts the given cmd and returns the Pid of the underlying
	// process.
	Start(context.Context, Cmd) (Pid, error)

	// Signal sends a signal to the running process.
	Signal(Pid, syscall.Signal) error

	io.Closer
}

Executor is the public facing API of a workspace's command execution.

type File

type File interface {
	Name() string
	Stat() (os.FileInfo, error)
	Sync() error
	Truncate(size int64) error
	Fd() uintptr

	io.Seeker
	io.Reader
	io.Closer
	io.Writer
	io.ReaderAt
}

File abstracts a subset of os.File.

type FileSystem

type FileSystem interface {
	URI(path string) (URI, error)

	// OpenFile opens a file at path with the given flag and mode.
	OpenFile(path string, flag int, mode os.FileMode) (File, error)

	// Remove removes the file at path.
	Remove(path string) error

	// Stat returns a FileInfo describing the named file.
	Stat(path string) (os.FileInfo, error)

	// ReadDir reads the named directory, returning all its directory entries.
	ReadDir(name string) ([]os.DirEntry, error)

	// MkdirAll creates a directory named path, along with any necessary parents,
	// and returns nil, or else returns an error. The permission bits perm (before
	// umask) are used for all directories that MkdirAll creates. If path is
	// already a directory, MkdirAll does nothing and returns nil.
	MkdirAll(path string, perm os.FileMode) error
}

FileSystem abstracts the public facing API of a workspace file system.

type Pid

type Pid int

Pid is an Executor's command identifier. It doesn't necessarily translate to an os.Process.Pid.

type ProcessWatcher

type ProcessWatcher interface {

	// The returned error is nil if the command runs, has no problems copying
	// stdin, stdout, and stderr, and exits with a zero exit status.
	WatchProcess() chan error
}

ProcessWatcher adds the ability for wait a processes started by Cmd and collect any I/O errors or non-zero exit code.

func ChanProcessWatcher

func ChanProcessWatcher(ch chan error) ProcessWatcher

ChanProcessWatcher returns a ProcessWatcher that simply returns ch when Watch is called.

func MultiProcessWatcher

func MultiProcessWatcher(watchers ...ProcessWatcher) ProcessWatcher

MultiProcessWatcher returns a ProcessWatcher that ensures that all the given watchers get notified when the process is done.

type Pty

type Pty struct {
	// Master is the pty master device file.
	Master File
	// Slave is the pseudoterminal slave device path.
	Slave File
}

Pty is a pseudoterminal on a Workspace.

type Terminal

type Terminal interface {
	// StartPty creates a new pseudoterminal.
	StartPty() (Pty, error)

	// SetPtySize sets the width and height in columns and rows of
	// a pseudoterminal.
	SetPtySize(p Pty, width, height int) error
}

Terminal abstracts the ability to manage pseudoterminals.

type URI

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

URI represents a parsed URI reference.

func CurrentUserHostURI

func CurrentUserHostURI(path string) (URI, error)

CurrentUserHostURI builds a URI from a path. If path is relative it uses the current working directory as the base of the path and if ~ is used to identify the home directory, the current user's home directory is used as the base. This should only used instead of Manager.URI before a workspace.Manager is constructed or for other advanced uses cases.

func Dir

func Dir(uri URI) URI

Dir returns all but the last element of this URI's path.

func Join

func Join(uri URI, elem ...string) URI

Join joins any number of path elements into this URI's path, separating them with slashes. For more details see path.Join.

func ParseURI

func ParseURI(s string) (URI, error)

ParseURI parses s as a URI in the form of: [scheme:][//[userinfo@]host][/]path[?query][#fragment]

func RandomURI

func RandomURI(scheme string) URI

RandomURI generates a random URI with the given scheme.

Under the hood it uses math.Rand so clients can manage seeding the default rand.Source, if desired.

func WithPath

func WithPath(u URI, path string) (URI, error)

WithPath maps the given URI to returns a URI with the same components but path set to path.

func (URI) Equal

func (u URI) Equal(other URI) bool

Equal returns true if this uri is equal to other.

func (URI) Host

func (u URI) Host() string

Host returns the host of this URI or an empty string if host is not specified.

func (URI) Hostname

func (u URI) Hostname() string

Hostname returns the hostname of this URI or an empty string if hostname is not specified.

func (URI) Name

func (u URI) Name() string

Name returns a short and non-unique representation of this URI.

func (URI) Password

func (u URI) Password() (string, bool)

Password returns the password of this URI or an empty string if a password is not specified.

func (URI) Path

func (u URI) Path() string

Path relative or absolute path component of this URI.

func (URI) Port

func (u URI) Port() string

Port returns the port of this URI or an empty string if port is not specified.

func (URI) Scheme

func (u URI) Scheme() string

Scheme returns the scheme of this URI.

func (URI) String

func (u URI) String() string

String returns the full string representation of this URI. The result can be fed back into ParseURI to get back a URI.

func (URI) User

func (u URI) User() string

User returns the user of this URI or an empty string if a user is not specified.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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