sessiondir

package
v0.8.6 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 16 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 sessiondir lets short commands reach a running pedit session on the same machine: a session registers a directory of its own under the user's configuration, and a command leaves a request there and waits for the answer (docs/design/comments-cli.md). Nothing in it names a path on disk or holds a key.

Index

Constants

View Source
const (
	OpList    = "list"
	OpReply   = "reply"
	OpResolve = "resolve"
	OpReopen  = "reopen"
)

The ops of a Request.

View Source
const MaxRequestBytes = 64 << 10

MaxRequestBytes bounds a request: a comment is at most 4,000 UTF-16 code units, which JSON writes in less.

View Source
const Version = 1

Version is the version of the files this package writes and reads.

Variables

View Source
var (
	// ErrWithdrawn means the session did not take the request in time, and
	// it was withdrawn: nothing was done.
	ErrWithdrawn = errors.New("the session did not answer; nothing was done")
	// ErrUnknown means the session took the request but did not answer in
	// time: what it did is not known.
	ErrUnknown = errors.New("the session took the request but did not answer in time")
	// ErrGone means the session ended before the request was left for it:
	// nothing was done.
	ErrGone = errors.New("the session ended")
)

Errors of Call.

Functions

func Base

func Base() (string, error)

Base is where sessions register: <UserConfigDir>/pedit/sessions.

Types

type Anchor

type Anchor struct {
	Type string `json:"type"`
	ID   string `json:"id,omitempty"`
}

Anchor is the kind of place a thread is on, and the node's id for a canvas node.

type Answer

type Answer struct {
	Version   int      `json:"version"`
	OK        bool     `json:"ok"`
	Error     string   `json:"error,omitempty"`
	Message   string   `json:"message,omitempty"`
	Delivered *bool    `json:"delivered,omitempty"`
	Threads   []Thread `json:"threads,omitempty"`
}

Answer is a session's answer to a Request.

type Dir

type Dir struct {
	ID string
	// contains filtered or unexported fields
}

Dir is the directory of a running session.

func Register

func Register(base string, info Info) (*Dir, error)

Register makes the directory of a session under base, private to the user, takes its lock and writes info.

func (*Dir) Close

func (d *Dir) Close()

Close stops serving, waits for the requests under way, and removes the directory.

func (*Dir) Serve

func (d *Dir) Serve(handle func(Request) Answer) error

Serve hands each request left for the session to handle, each on a goroutine of its own, and writes its answer. A request is taken by moving it out of req/, so a command that gives up at the same time withdraws it or finds it taken, never both.

type Info

type Info struct {
	Version int      `json:"version"`
	PID     int      `json:"pid"`
	Room    string   `json:"room"`
	Access  string   `json:"access"`
	Project string   `json:"project,omitempty"`
	Name    string   `json:"name"`
	Files   []string `json:"files"`
}

Info is what a session tells about itself, in session.json.

type Live

type Live struct {
	ID   string
	Info Info
	// contains filtered or unexported fields
}

Live is a session found running.

func List

func List(base string) ([]Live, error)

List lists the sessions running under base. The directory of a session whose lock is free ended without cleaning up, and is removed.

func (Live) Call

func (l Live) Call(req Request, wait time.Duration) (Answer, error)

Call leaves req for the session and waits up to wait for its answer.

type Message

type Message struct {
	ID     string `json:"id"`
	Author string `json:"author"`
	Time   string `json:"time"`
	Body   string `json:"body"`
}

Message is one comment of a Thread.

type Request

type Request struct {
	Version int    `json:"version"`
	Op      string `json:"op"`
	File    string `json:"file"`
	Thread  string `json:"thread"`
	Message string `json:"message"`
	Body    string `json:"body"`
}

Request is what a command asks of a session.

type Thread

type Thread struct {
	File     string    `json:"file"`
	Thread   string    `json:"thread"`
	Anchor   Anchor    `json:"anchor"`
	Quote    string    `json:"quote"`
	Resolved bool      `json:"resolved"`
	Messages []Message `json:"messages"`
}

Thread is a comment thread as pedit comments list --json prints it.

Jump to

Keyboard shortcuts

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