docshare

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: 18 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 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

View Source
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

func FormatOf

func FormatOf(path string) string

FormatOf is "md" or "html" for a file name the first version takes, else "".

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.

func (*Failure) Error

func (f *Failure) Error() string

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

type Request struct {
	Path         string
	Conversation string
}

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 New

func New(cfg Config) *Service

New prepares a service.

func (*Service) Publish

func (s *Service) Publish(req Request) (State, *Failure)

Publish makes the document of a file, private. A file that is linked already answers with its document.

func (*Service) Run

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

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.

func (*Service) State

func (s *Service) State(path string) State

State is the file's state; a file nobody shared answers {Shared: false}.

func (*Service) Tick

func (s *Service) Tick()

Tick looks at every linked file once: a changed one, with its last version older than the debounce, becomes a new version.

func (s *Service) Unlink(path string) (State, bool)

Unlink freezes the document: later saves of the file are not published. The document stays as it is.

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 {
	Shared  bool   `json:"shared"`
	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.

Jump to

Keyboard shortcuts

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