server

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 24 Imported by: 0

README

#+TITLE: Leisure server
HTTP server and command line tools for Leisure.

* API
** Create a document
- =/v1/doc/create/ID=
- =/v1/doc/create/ID?alias=ALIAS=

If no ID is given one will be created

Body is the document content

Returns a JSON string  the document ID

** list documents
- =/v1/doc/list=

returns a JSON list of each document and its alias (or null if there is none)

** Create a session
- =/v1/session/create/=

** Connect and get a session key
- =/v1/session/connect/SESSION_NAME=
- =/v1/session/connect/SESSION_NAME?docId=ID=

With docId, it will automatically create a session on the given document

** List sessions
- =/v1/session/list=

** Get the document for a session
- =/v1/session/get/=

** Make replacements in a session
- =/v1/session/replace=

Body is a JSON struct like this:

#+begin_src json
{...}
#+end_src


** Check for an update
- =/v1/session/update=?minutes=2

Will wait for a given number of minutes for an update (defaults to 2). If this returns true,
there is an update and the client should make a replacement.

Documentation

Index

Constants

View Source
const (
	VERSION          = "/v1"
	DOC_CREATE       = VERSION + "/doc/create/"
	DOC_GET          = VERSION + "/doc/get/"
	DOC_LIST         = VERSION + "/doc/list"
	SESSION_CLOSE    = VERSION + "/session/close"
	SESSION_CONNECT  = VERSION + "/session/connect/"
	SESSION_CREATE   = VERSION + "/session/create/"
	SESSION_LIST     = VERSION + "/session/list"
	SESSION_DOCUMENT = VERSION + "/session/document"
	SESSION_EDIT     = VERSION + "/session/edit"
	SESSION_UPDATE   = VERSION + "/session/update"
	SESSION_GET      = VERSION + "/session/get/"
	SESSION_SET      = VERSION + "/session/set/"
	SESSION_REMOVE   = VERSION + "/session/remove/"
	ORG_PARSE        = VERSION + "/org/parse"
)
View Source
const (
	DEFAULT_COOKIE_TIMEOUT = 5 * time.Minute
)
View Source
const JSON_TAG = `(^|,)json:"([^"]+)"`
View Source
const UPDATE_TIME = 2 * time.Minute

Variables

View Source
var ErrCommandFormat = NewLeisureError("badCommandFormat")
View Source
var ErrDataMismatch = NewLeisureError("dataMismatch")
View Source
var ErrDataMissing = NewLeisureError("dataMissing")
View Source
var ErrDocumentAliasExists = NewLeisureError("documentAliasExists")
View Source
var ErrDocumentExists = NewLeisureError("documentExists")
View Source
var ErrDuplicateConnection = NewLeisureError("duplicateConnection")
View Source
var ErrDuplicateSession = NewLeisureError("duplicateSession")
View Source
var ErrExpiredSession = NewLeisureError("expiredSession")
View Source
var ErrInternalError = NewLeisureError("internalError")
View Source
var ErrUnknown = NewLeisureError("unknownError")
View Source
var ErrUnknownDocument = NewLeisureError("unknownDocument")
View Source
var ErrUnknownSession = NewLeisureError("unknownSession")

Functions

func ErrorData added in v0.0.1

func ErrorData(errObj any) map[string]any

func ErrorJSON added in v0.0.1

func ErrorJSON(err any) string

func ErrorJSONBytes added in v0.0.1

func ErrorJSONBytes(err any) []byte

func ErrorType added in v0.0.1

func ErrorType(errObj any) string

func MemoryStorage

func MemoryStorage(id, content string) hist.DocStorage

Types

type LeisureContext added in v0.0.1

type LeisureContext struct {
	*LeisureService
	// contains filtered or unexported fields
}

type LeisureError added in v0.0.1

type LeisureError struct {
	Type string
	Data map[string]any
	// contains filtered or unexported fields
}

func NewLeisureError added in v0.0.1

func NewLeisureError(errorType string, values ...any) LeisureError

func (LeisureError) Error added in v0.0.1

func (err LeisureError) Error() string

func (LeisureError) Unwrap added in v0.0.1

func (err LeisureError) Unwrap() error

type LeisureService

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

func Initialize

func Initialize(id string, mux *http.ServeMux, storageFactory func(string, string) hist.DocStorage) *LeisureService

func NewWebService

func NewWebService(id string, storageFactory func(string, string) hist.DocStorage) *LeisureService

func (*LeisureService) SetVerbose added in v0.0.1

func (sv *LeisureService) SetVerbose(n int)

type LeisureSession

type LeisureSession struct {
	*history.History
	Peer       string
	SessionId  string
	PendingOps []doc.Replacement
	Follow     string // track a sessionId when making new commits
	// contains filtered or unexported fields
}

func (*LeisureSession) Commit added in v0.0.8

func (s *LeisureSession) Commit(selOff int, selLen int) ([]doc.Replacement, int, int)

commit pending ops into an opBlock, get its document, and return the replacements these will unwind the current document to the common ancestor and replay to the current version

func (*LeisureSession) Replace added in v0.0.8

func (s *LeisureSession) Replace(offset int, length int, text string)

add a replacement to pendingOps

func (*LeisureSession) ReplaceAll added in v0.0.8

func (s *LeisureSession) ReplaceAll(replacements []doc.Replacement)

add a replacement to pendingOps

type Sha added in v0.0.1

type Sha = [sha256.Size]byte

Jump to

Keyboard shortcuts

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