services

package
v0.16.86 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 34 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package services answers the runtime's routes that only call external services with the person's tokens: a session's pushes and merge requests on GitLab, a merge request or commit with its diff, link previews (tracker issues, merge requests, published documents), tracker avatars, project keys and task cards, and site icons. The organizer (a small file of the person's own) and the page's start data are here too. Answers, caches and their lifetimes are the previous runtime's; the GitLab walk asks git only what it needs, runs its requests in parallel and keeps their answers a few seconds.

Index

Constants

View Source
const (
	TaskNotFound = "not-found"
	TaskNoToken  = "no-token"
	TaskTracker  = "tracker"
)

Task errors and their statuses.

Variables

View Source
var ErrOrganizerUnreadable = errors.New("organizer-unreadable")

ErrOrganizerUnreadable: the file exists but cannot be trusted; the route answers 500.

View Source
var (
	// HostRe is a host name the icon route serves.
	HostRe = regexp.MustCompile(`^[a-z0-9-]{1,63}(\.[a-z0-9-]{1,63})+$`)
)
View Source
var LoginRe = regexp.MustCompile(`^[\w.@-]{1,100}$`)

LoginRe is a tracker login the avatar route serves.

Functions

func GitLabSelfToken added in v0.16.86

func GitLabSelfToken(cfg Config) string

GitLabSelfToken is the token of the deployment's own GitLab (the first of GitLabHosts) as the GitLab routes read it; "" without one.

func OriginOf

func OriginOf(raw string) string

OriginOf is the origin of an http(s) address (scheme, host and non-default port), "" for anything else. A deployment names its documents and boards services by it.

func TrackerToken added in v0.16.86

func TrackerToken(cfg Config) string

TrackerToken is the deployment tracker's token as the tracker routes read it (YOUTRACK_TOKEN, else a youtrack-token file in a secret folder of a home); "" without a tracker or a token. Read on every call.

func ValidIconHost

func ValidIconHost(host string) bool

ValidIconHost: a public name, not an address, not a local or internal one.

Types

type Bootstrap

type Bootstrap struct {
	DataDir string
	// ConfigFile is the runtime's settings file.
	ConfigFile string
	// HostLocked: the deployment fixed the listening address (the previous runtime's HOST).
	HostLocked bool
	// BindLocal: the previous runtime listens on loopback only.
	BindLocal bool
	// Owner is the person a request's session names (its token's sub), nil without one.
	Owner func(*http.Request) any
	// Tools reports whether tmux (a compatible one) and git are installed; it may be slow.
	Tools func() bool
	// CreateFirst makes the machine's first workspace when it has none, before the answer is read; nil leaves an empty
	// machine empty.
	CreateFirst func() error
	Now         func() time.Time
	// contains filtered or unexported fields
}

Bootstrap answers the page's start data from this machine's files: the person, whether tmux and git are usable, the workspaces, the settings without their secrets, the quick prompts and the sidebar items. Creating the first workspace of an empty machine is the layout store's work (CreateFirst).

func (*Bootstrap) HasWorkspaces

func (b *Bootstrap) HasWorkspaces() bool

HasWorkspaces: the machine has a workspace already, so the answer needs no new one.

func (*Bootstrap) Serve

func (b *Bootstrap) Serve(w http.ResponseWriter, r *http.Request)

Serve is GET /bootstrap.

type Config

type Config struct {
	// Home is the runtime user's home: Claude Code and Codex transcripts are under it.
	Home string
	// SecretDirs are home-relative folders that hold token files (".config/<app>"), searched in order.
	SecretDirs []string
	// GitLabHosts are the GitLabs links and remotes may point at; the first is the self-hosted one, which reads its
	// own token.
	GitLabHosts []string
	// GitLabAPI is the origin the GitLab API is read from when it is not https://<host> (a stand-in in the browser
	// tests); empty for the GitLabs themselves.
	GitLabAPI string
	// GitHubHost is the GitHub whose pull requests, commits and issues a tab shows ("" is github.com); GitHubAPI the
	// origin its API is read from when it is not the host's own (a stand-in in tests). GitHubTokenCmd asks for the
	// person's token (nil is `gh auth token`).
	GitHubHost, GitHubAPI string
	GitHubTokenCmd        []string
	// TrackerURL is the issue tracker's origin (https://tracker.example.com); TrackerHosts the hosts its issue links use.
	TrackerURL   string
	TrackerHosts []string
	// DocsHost serves published documents (/a/<slug>) and boards (/b/<slug>); ReaderHost and ReaderPath are where the
	// platform shows the same document.
	DocsHost string
	// PortalOrigins are the origins (scheme, host and port) of the documents and boards services when they are not one
	// https host: a workspace on http://localhost with a port per service. Links on them get the same metadata as links
	// on DocsHost. The first one is where the platform's reader links are mapped to.
	PortalOrigins []string
	ReaderHost    string
	ReaderPath    string
	// TaskKey is a task key the task card serves.
	TaskKey *regexp.Regexp
	// AvatarPath is the route that serves tracker avatars, as the page loads it.
	AvatarPath string
	// IconAgent is the User-Agent of site icon requests.
	IconAgent string
	// OrganizerFile is the person's organizer.
	OrganizerFile string
	// Transport carries every outgoing request; nil is the default one.
	Transport http.RoundTripper
	// Connections are the person's trackers and wikis (internal/connections); nil for none. The tracker app, task cards
	// and link previews read a connection that is not the deployment's tracker through it.
	Connections *connections.Service
}

Config is what the deployment names.

type Handlers

type Handlers struct {
	S *Service
	// Session: the request carries a page session (a cli-token alone is not a person).
	Session func(*http.Request) bool
	// Now is the clock of the organizer's timestamps; nil is time.Now.
	Now func() time.Time
}

Handlers answer the routes as the previous runtime's dispatcher and handlers did, after the caller passed the API's own check (a page session or the cli-token): the body read first (413, "Invalid JSON"), then each handler's session check, statuses, headers, JSON with its ETag and 304, and the plain 500 of a handler that threw.

func (*Handlers) Avatar

func (h *Handlers) Avatar(w http.ResponseWriter, r *http.Request)

Avatar: ?login=, a tracker user's avatar, any method.

func (*Handlers) ChangeView added in v0.15.40

func (h *Handlers) ChangeView(w http.ResponseWriter, r *http.Request)

ChangeView: GET ?url=, a merge request, pull request, commit or issue of GitLab or GitHub with its checks, discussion and diff. A GitHub link that cannot be read answers a card with the reason (200), so the tab is never empty.

func (*Handlers) Favicon

func (h *Handlers) Favicon(w http.ResponseWriter, r *http.Request)

Favicon: ?host=, a public site's icon, any method.

func (*Handlers) GitLab

func (h *Handlers) GitLab(w http.ResponseWriter, r *http.Request)

GitLab: POST {paths, jsonlPath, mrs}, a session's pushes and merge requests with live pipeline status.

func (*Handlers) GitLabView

func (h *Handlers) GitLabView(w http.ResponseWriter, r *http.Request)

GitLabView: GET ?url=, a merge request or a commit with its diff.

func (*Handlers) LinkMeta

func (h *Handlers) LinkMeta(w http.ResponseWriter, r *http.Request)

LinkMeta: GET ?url= (a tracker issue, a merge request, a published document) or ?key= (a bare task key).

func (*Handlers) Organizer

func (h *Handlers) Organizer(w http.ResponseWriter, r *http.Request)

Organizer: GET reads the person's projects and pins, PATCH {ops} changes them.

func (*Handlers) Projects

func (h *Handlers) Projects(w http.ResponseWriter, r *http.Request)

Projects: the tracker's project keys, any method.

func (*Handlers) Task

func (h *Handlers) Task(w http.ResponseWriter, r *http.Request)

Task: GET ?key=[&conn=], a tracker task for the card: a key of the deployment's tracker as before, else an issue of the connection conn names (the primary one with issues when none is named).

type Image

type Image struct {
	Type string
	Body []byte
}

Image is a picture fetched for the page.

type MergeRequestInfo added in v0.15.40

type MergeRequestInfo struct {
	URL   string
	Title string
	// UpdatedAt is when it last changed, as GitLab wrote it (RFC 3339); "" when it did not say.
	UpdatedAt string
}

MergeRequestInfo is a merge request GitLab gave: where it lives now (a renamed project answers under its new path) and what it is called.

type OrganizerError

type OrganizerError struct {
	Status int
	Body   *jsvalue.Object
}

OrganizerError is a refused change: its status and body.

func ParseOrganizerOps

func ParseOrganizerOps(body any) ([]*organizerOp, *OrganizerError)

ParseOrganizerOps validates a PATCH body: {ops: [1..50 ops]}.

type Service

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

Service holds the caches the answers share.

func New

func New(cfg Config) *Service

func (*Service) ApplyOrganizer

func (s *Service) ApplyOrganizer(ops []*organizerOp, nowMs float64) (*jsvalue.Object, *OrganizerError, error)

ApplyOrganizer applies every op, all or nothing, and writes the file only when something changed.

func (*Service) Apps added in v0.15.40

func (s *Service) Apps(ctx context.Context) wire.AppsFeed

Apps reads every app of the screen, in parallel. An answer is kept for appsFresh; one that is not ready is not kept, so a token put in place is taken on the next look.

func (*Service) ChangeView added in v0.15.40

func (s *Service) ChangeView(ctx context.Context, raw string) (*jsvalue.Object, error)

ChangeView is the change a link names with its checks and discussion. nil when the service does not give it to this token (GitLab) — GitHub answers a card with the reason instead, so the tab never stays empty.

func (*Service) ConnTask added in v0.16.86

func (s *Service) ConnTask(ctx context.Context, conn, key string) (*jsvalue.Object, string)

ConnTask is one issue of a connection for the card, kept and shared like Task. Callers check ConnTaskKey first.

func (*Service) ConnTaskKey added in v0.16.86

func (s *Service) ConnTaskKey(conn, key string) bool

ConnTaskKey says whether the card serves key from a connection: conn names it ("" is the personal one), and the key is not one the deployment's tracker serves.

func (*Service) GitLabView

func (s *Service) GitLabView(ctx context.Context, raw string) (*jsvalue.Object, error)

GitLabView is what a tab shows of a merge request or a commit; nil when GitLab does not give it to this token.

func (*Service) IsChangeRef added in v0.15.40

func (s *Service) IsChangeRef(raw string) bool

IsChangeRef: the change view serves this link.

func (*Service) IsGitLabRef

func (s *Service) IsGitLabRef(raw string) bool

IsGitLabRef: the view route serves this link.

func (*Service) IsTaskKey

func (s *Service) IsTaskKey(v any) bool

IsTaskKey: a key of a tracker space the card serves.

func (*Service) MergeRequest added in v0.15.40

func (s *Service) MergeRequest(ctx context.Context, host, project string, iid int) (MergeRequestInfo, bool)

MergeRequest asks the GitLab at host, with its own token, for the merge request numbered iid of a project path. false for any "no": the merge request or the project is not there, the token cannot see it, there is no token, the GitLab is not reachable or is not one of the deployment's. The answers are shared with the tab that shows it.

func (*Service) Organizer

func (s *Service) Organizer() (*jsvalue.Object, error)

Organizer reads the file: an empty organizer when there is none yet.

func (*Service) ProjectKeys

func (s *Service) ProjectKeys(ctx context.Context) ([]any, error)

ProjectKeys are the short names of the tracker's live projects, kept an hour; a failed read gives the last list.

func (*Service) ProjectPaths added in v0.15.40

func (s *Service) ProjectPaths(ctx context.Context, host, name string) []string

ProjectPaths are the paths (group/sub/project) of the projects of the GitLab at host whose last segment is name, as its search finds them with the host's own token; nil for any "no". The answer is shared like the rest.

func (*Service) SessionGitLab

func (s *Service) SessionGitLab(ctx context.Context, paths []string, since *float64, mentioned []string) (*jsvalue.Object, error)

SessionGitLab is what a session sent to GitLab: its branches with their last pipeline, and the merge requests with theirs. since is the session's start (ms), nil without a transcript; a commit of the session is what makes a repository count, so without one no git or GitLab work is needed for the repositories.

func (*Service) SiteIcon

func (s *Service) SiteIcon(ctx context.Context, host string) *Image

SiteIcon is a site's icon, kept a day (a miss an hour).

func (*Service) Task

func (s *Service) Task(ctx context.Context, key string) (*jsvalue.Object, string)

Task is one tracker task: one request per task, kept a minute, shared while in flight; a failure is never kept. err is one of the Task* errors.

func (*Service) TrackerAvatar

func (s *Service) TrackerAvatar(ctx context.Context, login string) (*Image, error)

TrackerAvatar is a tracker user's avatar, fetched with the server's token so the browser never needs it.

Jump to

Keyboard shortcuts

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