workspace

package
v0.18.1 Latest Latest
Warning

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

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

Documentation

Overview

Package workspace mounts additional gadak profiles under /w/<name>/ and lists them at GET /api/v1/workspaces. Shared by `gadak serve` and the desktop app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListHandler

func ListHandler() http.HandlerFunc

ListHandler answers GET /api/v1/workspaces with the primary profile first (active:true) and every named profile after. Credentials never appear.

func Prefix added in v0.15.0

func Prefix(profile, served string) string

Prefix is the path segment that selects `profile` on a server whose primary profile is `served`: "" when they are the same mirror, "/w/<name>" when the profile has to be reached as a workspace mount.

Callers join it ahead of the rest of the path, so the empty string is the correct answer for the primary profile and not a missing value.

func ProfileEq added in v0.15.0

func ProfileEq(got, want string) bool

ProfileEq reports whether two profile names mean the same mirror. The primary profile answers to both "" and "default" — the config layer stores it empty, humans and URLs write it out — so a comparison that misses this sends `gadak views open` to /w/default on the very server it is talking to.

func ProfileExists

func ProfileExists(name string) bool

ProfileExists reports whether name is a directory under profiles/ (disk is the source of truth for workspace mounts).

Types

type Entry

type Entry struct {
	// Handler is the concrete server handler, not http.Handler: this entry
	// owns its lifetime, and Close has to be able to stop the background sync
	// before the mirror it writes to is closed (GDK-270).
	Handler *server.Handler
	DB      *store.DB
	Cfg     *config.Config
	// contains filtered or unexported fields
}

Entry is one opened workspace mirror (handler + DB + config).

type ListEntry

type ListEntry struct {
	Name     string   `json:"name"`
	Site     string   `json:"site,omitempty"`
	Projects []string `json:"projects,omitempty"`
	Active   bool     `json:"active,omitempty"`
	Error    string   `json:"error,omitempty"`
}

ListEntry is one item in GET /api/v1/workspaces. Never carries Token or Email — only site URL and project keys for the picker.

type Registry

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

Registry lazy-opens profile mirrors on first /w/<name>/ request and closes them when the process exits.

func New

func New() *Registry

New returns an empty workspace registry.

func (*Registry) Close

func (r *Registry) Close()

Close closes every opened workspace DB. Safe to call once at shutdown. In-flight constructors are waited on (they see closed and close their own object) so this never closes a half-built entry.

func (*Registry) EnsureOrigins added in v0.18.0

func (r *Registry) EnsureOrigins()

EnsureOrigins retries ownership for every opened entry. The rescan loop calls this so a failed bind heals within watchRescanInterval.

func (*Registry) EnsureWatch added in v0.13.0

func (r *Registry) EnsureWatch(name string) bool

EnsureWatch starts this profile's Watch if WatchAll has armed the owner, the profile now has a credential, and no loop is already running. Idempotent. LoadFor and store.Open run with r.mu released.

func (*Registry) EnsureWatches added in v0.13.0

func (r *Registry) EnsureWatches() []string

EnsureWatches is the single "credential appeared" scan: start a Watch for every non-primary profile that now has a credential and does not already have a loop. Returns the names that were started this call.

func (*Registry) Get

func (r *Registry) Get(name string) (*Entry, error)

Get returns a cached workspace entry, opening the profile on first use.

func (*Registry) Handler

func (r *Registry) Handler(spa http.Handler, version string) http.HandlerFunc

Handler routes /w/<name>/… to the named profile's API, config, healthz, or SPA. Invalid names and unknown profiles answer 404. version is reported in healthz (same field as the primary /healthz).

func (*Registry) WatchAll

func (r *Registry) WatchAll(ctx context.Context, primary string, logf func(string)) []string

WatchAll arms the credential-appearance owner and starts a loop for every profile that already has a credential, skipping primary (its caller already watches that one). Returns the profile names that got a loop. Subsequent credentials (onboarding connect, or a later EnsureWatches / rescan) start through the same owner and cannot double-start. Log receives status lines; never pass secrets into it — only profile names are logged from here.

Jump to

Keyboard shortcuts

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