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
- Variables
- func OriginOf(raw string) string
- func ValidIconHost(host string) bool
- type Bootstrap
- type Config
- type Handlers
- func (h *Handlers) Avatar(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Favicon(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GitLab(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) GitLabView(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) LinkMeta(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Organizer(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Projects(w http.ResponseWriter, r *http.Request)
- func (h *Handlers) Task(w http.ResponseWriter, r *http.Request)
- type Image
- type OrganizerError
- type Service
- func (s *Service) ApplyOrganizer(ops []*organizerOp, nowMs float64) (*jsvalue.Object, *OrganizerError, error)
- func (s *Service) GitLabView(ctx context.Context, raw string) (*jsvalue.Object, error)
- func (s *Service) IsGitLabRef(raw string) bool
- func (s *Service) IsTaskKey(v any) bool
- func (s *Service) Organizer() (*jsvalue.Object, error)
- func (s *Service) ProjectKeys(ctx context.Context) ([]any, error)
- func (s *Service) SessionGitLab(ctx context.Context, paths []string, since *float64, mentioned []string) (*jsvalue.Object, error)
- func (s *Service) SiteIcon(ctx context.Context, host string) *Image
- func (s *Service) Task(ctx context.Context, key string) (*jsvalue.Object, string)
- func (s *Service) TrackerAvatar(ctx context.Context, login string) (*Image, error)
Constants ¶
const ( TaskNotFound = "not-found" TaskNoToken = "no-token" TaskTracker = "tracker" )
Task errors and their statuses.
Variables ¶
var ErrOrganizerUnreadable = errors.New("organizer-unreadable")
ErrOrganizerUnreadable: the file exists but cannot be trusted; the route answers 500.
var ( // HostRe is a host name the icon route serves. HostRe = regexp.MustCompile(`^[a-z0-9-]{1,63}(\.[a-z0-9-]{1,63})+$`) )
var LoginRe = regexp.MustCompile(`^[\w.@-]{1,100}$`)
LoginRe is a tracker login the avatar route serves.
Functions ¶
func OriginOf ¶
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 ¶
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 ¶
HasWorkspaces: the machine has a workspace already, so the answer needs no new one.
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.
type OrganizerError ¶
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 (*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 ¶
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 ¶
IsGitLabRef: the view route serves this link.
func (*Service) ProjectKeys ¶
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.