services

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 29 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 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 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
	// 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
}

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) 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=, a tracker task for the card.

type Image

type Image struct {
	Type string
	Body []byte
}

Image is a picture fetched for the page.

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) 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) 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) 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) 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