Documentation
¶
Overview ¶
Package docshare turns a file of the workspace into a document of the cluster's catalog and keeps the two bound: every save of a linked file, by the person in the editor or by an agent, becomes a new version of the document, no more often than once in Debounce. The file stays the working copy; the document is private to its owner until the person opens it (the access dialog, or the artifact CLI). The way to the cluster is the machine agent's loopback route /docs/publish (internal/agent/docrelay.go).
Index ¶
Constants ¶
const ( // FileName is the registry of sources in the data directory. FileName = "doc-shares.json" // MaxBytes is the biggest document: what the editor opens. MaxBytes = 1_000_000 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
DataDir string
AgentTokenHeader string
HTTP *http.Client
Now func() time.Time
Debounce time.Duration
Poll time.Duration
// Call posts to the machine agent; the default is agent.CallLocal. Tests put their own.
Call func(route string, body any) (int, []byte, error)
// Publisher, when set, publishes instead of the machine agent: the runtime sets it when a documents adapter is
// declared, so a shared file becomes a document of that service, bound to its conversation (GitHub issue 26).
Publisher Publisher
}
Config is the service's setting.
type Failure ¶
type Failure struct {
Status int
Text string
// Line is the first line of a secret, when that is the reason.
Line int
Kind string
}
Failure is a refusal with the status the page gets.
type Publication ¶
type Publication struct {
Title, Format, Content, Slug, Path, Conversation, Note string
}
Publication is one version of a file to publish.
type Publisher ¶
type Publisher func(p Publication) (version int, slug string, fail *Failure)
Publisher publishes one version of a file and answers its version and slug.
type Request ¶
Request is "Поделиться" for a file: the absolute, resolved path of a file already checked to lie in the person's project.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service keeps the registry and watches the linked files.
func (*Service) Publish ¶
Publish makes the document of a file, private. A file that is linked already answers with its document.
func (*Service) Run ¶
Run watches the linked files until ctx ends. With no linked file there is nothing to look at: it waits for the first one to be shared.
type Source ¶
type Source struct {
Path string `json:"path"`
Slug string `json:"slug"`
Title string `json:"title"`
Conversation string `json:"conversation,omitempty"`
Hash string `json:"hash"`
Version int `json:"version"`
Linked bool `json:"linked"`
PublishedAt time.Time `json:"publishedAt"`
// RefusedHash is the content a republish was refused for (a secret), so it is not tried again until the file changes.
RefusedHash string `json:"refusedHash,omitempty"`
// RefusedLine is the line of the secret in RefusedHash.
RefusedLine int `json:"refusedLine,omitempty"`
}
Source is a file and the document made of it.
type State ¶
type State struct {
Slug string `json:"slug,omitempty"`
Linked bool `json:"linked"`
Version int `json:"version,omitempty"`
// Pending: the file has changed since the document was made; the next version waits for the debounce.
Pending bool `json:"pending,omitempty"`
// RefusedLine: the newest content holds a secret on this line and is not published.
RefusedLine int `json:"refusedLine,omitempty"`
}
State is what the page shows for a file.