docs

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.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 docs is the hub's side of documents and boards (docs/hub/docs.md): the page's document API (<platform api>/docs), which the web core calls, and the agents' doc.publish and doc.acl, which the machine's agent sends over its link. The documents themselves live in the documents service (github.com/ly-solutions/artifacts), the boards in the boards service; the hub keeps what neither has: who owns a document and who else may open it, the comment threads and what each person has read.

It is switched on by HUB_DOCS. Without the flag, or without the address and token of the documents service, every route answers 503 with {error, code: "docs_not_configured", reason} and the page says what is missing.

Index

Constants

View Source
const (
	ServiceDocuments = "documents"
	ServiceBoards    = "boards"
)

The services the hub probes, as the status names them.

View Source
const (
	RightNone    = "none"
	RightView    = "view"
	RightComment = "comment"
	RightEdit    = "edit"
)

Rights a person has on a document, as the service is told.

View Source
const SwitchBoardEvents = "hub-board-events"

SwitchBoardEvents is the rollout switch (docs/hub/rollout-switches.md) that makes the hub take the events of the boards a person drew; for the others the hub passes them on or drops them.

Variables

View Source
var ErrNoReadyz = errors.New("the address does not route /readyz")

ErrNoReadyz: the address answered 404 to /readyz. The service itself is not said to be down: the address only does not route that path (a public host that shows one prefix of the service is the usual case), so the answer tells nothing about the service. The status leaves such a service out and nobody is mailed; the doctor still reports it.

Functions

func LegacyRedirect

func LegacyRedirect(publicURL string) http.Handler

LegacyRedirect answers the old document address, /a/<slug> (HUB_DOCS_LEGACY_HOSTS), with a permanent redirect to the document's page in the hub's workspace. It serves no content: whether the person may read the document is decided there, by their sign-in and the document's own access, as for any link to it. Anything but /a/<slug> is 404.

func ProbeReady

func ProbeReady(ctx context.Context, hc *http.Client, base string) error

ProbeReady asks base/readyz and says why the service is not ready; nil: it answered 2xx. A 404 wraps ErrNoReadyz.

Types

type Bell

type Bell func(ctx context.Context, userID, email, key, title, text, link string) bool

Bell rings one hub user's bell: a notice without a chat, with a link; it reports whether the notice was put.

type Deps

type Deps struct {
	Config *config.Config
	DB     *store.DB
	Auth   *auth.Service
	Log    *slog.Logger
	Now    func() time.Time
	// LinkKey is the hub's own secret: the address of a resource's general link is kept sealed with a key derived
	// from it, so the share dialog can copy it again; nil keeps no address.
	LinkKey []byte
	// Links hands comments to the machines' conversations; nil keeps them on the hub.
	Links Linker
	// HTTP reaches the documents and boards services; nil: a client with a 30 second timeout.
	HTTP *http.Client
	// Notice tells a person by mail that they were mentioned; nil: nobody is told.
	Notice Notice
	// Gate says whether the rollout switch of the comments on boards is on for a person (boards.go); nil: off for everyone.
	Gate Gate
	// Bell rings a person's bell for a mention on a board (board_mentions.go); nil: nobody is told.
	Bell Bell
	// AppToken checks the platform's token of a person for an app's backend (the hub's signature, issuer, the audience
	// given and the expiry) and answers whose it is; nil: a service cannot act for a person (manage.go).
	AppToken func(token, audience string) (sub string, err error)
}

Deps are what the service needs from the hub.

type Gate

type Gate interface {
	On(ctx context.Context, feature, person, machine string) bool
}

Gate says whether a rollout switch is on for a person on a machine.

type Linker

type Linker interface {
	Get(machineID string) *link.Link
	Do(ctx context.Context, machineID, op string, params any, timeout time.Duration) (json.RawMessage, error)
}

Linker is the part of the machines' link registry delivery needs.

type Notice

type Notice func(ctx context.Context, to, subject, body, link string) error

Notice mails a short notice to a person (a mention); nil keeps the hub silent.

type Reply

type Reply struct {
	Status int
	Body   any
}

Reply is what the hub answers an agent's doc.publish or doc.acl: the agent turns it into the tool result.

type Service

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

Service serves documents and boards.

func New

func New(d Deps) *Service

func (*Service) Deliver

func (s *Service) Deliver(commentID string)

Deliver hands a person's new comment to the conversation of its document, in the background.

func (*Service) Event

func (s *Service) Event(l *link.Link, m store.Machine, ev link.Event)

Event takes the doc.publish and doc.acl events of a machine's link and answers each with the op doc.result. It returns at once; the answer is sent from a goroutine.

func (*Service) Handle

func (s *Service) Handle(ctx context.Context, who Who, kind string, raw json.RawMessage) (rid string, rep Reply, ok bool)

Handle answers one event of an agent; ok is false for an event that is not this package's. Without documents set up the agent gets a 503 it can show, never silence.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler answers the documents' routes alone, for the workspace (/agents/api/…) to hand them over; nil when the hub keeps no documents (HUB_DOCS off). Prefix is where those routes live.

func (*Service) Mount

func (s *Service) Mount(mux *http.ServeMux)

Mount adds the routes under the platform API prefix.

func (*Service) Prefix

func (s *Service) Prefix() string

Prefix is the documents' own path: <platform api>/docs.

func (*Service) Run

func (s *Service) Run(ctx context.Context)

Run probes the documents and boards services (health.go) and tries the comments not yet handed over again every minute until ctx ends, and gives up on those older than a day.

func (*Service) RunHealth

func (s *Service) RunHealth(ctx context.Context)

RunHealth probes the documents and boards services until ctx ends (every replica keeps its own view of them).

func (*Service) RunSweep

func (s *Service) RunSweep(ctx context.Context)

RunSweep tries the comments not yet handed over again every minute until ctx ends: with several replicas only the leader does it (docs/hub/replicas.md). It also sends the documents service the trash it has not confirmed yet (trashsync.go), at start and every minute.

func (*Service) Services

func (s *Service) Services() map[string]ServiceHealth

Services is the last known health of each probed service; a service not probed yet is absent.

func (*Service) Status

func (s *Service) Status() Status

type ServiceHealth

type ServiceHealth struct {
	Up        bool      `json:"up"`
	Since     time.Time `json:"since"`
	CheckedAt time.Time `json:"checkedAt"`
}

ServiceHealth is the last answer of one service. Since is when it last went up or down.

type Status

type Status struct {
	Enabled   bool   `json:"enabled"`
	Documents bool   `json:"documents"`
	Boards    bool   `json:"boards"`
	Reason    string `json:"reason,omitempty"`
	Text      string `json:"text,omitempty"`
	// Services is whether each configured service answers its /readyz (ServiceDocuments, ServiceBoards); a service not
	// asked yet is absent, and the page then takes it for up.
	Services map[string]ServiceHealth `json:"services,omitempty"`
}

Status says whether documents work and, when they do not, why. Reason is a code the page can match; Text is a sentence for the person.

type Who

type Who struct {
	MachineID string
	// OwnerID is the account that connected the machine.
	OwnerID string
	// SpaceID is the space the machine is in: what it publishes belongs there.
	SpaceID string
}

Who is the machine an event came from.

Jump to

Keyboard shortcuts

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