Documentation
¶
Overview ¶
Package remote talks to a self-hosted ZenNotes server over its HTTP API, the same routes the desktop and web clients use.
Index ¶
- Constants
- func ApplyHeaders(h http.Header, headers []Header)
- func ConnectionErrorMessage(baseURL string, err error) string
- func GatewayRefusedMessage(baseURL string) string
- func IsNoteChanged(err error) bool
- func IsSha256Hex(value string) bool
- func NormalizeBaseURL(value string) string
- func StatusOf(err error) int
- type AbsenceAwareReader
- type ChangeEvent
- type Client
- func (c *Client) ArchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (c *Client) Capabilities(ctx context.Context) (map[string]any, error)
- func (c *Client) CreateFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error
- func (c *Client) CreateNote(ctx context.Context, folder vault.NoteFolder, title, subpath string) (vault.NoteMeta, error)
- func (c *Client) DeleteFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error
- func (c *Client) DeleteNote(ctx context.Context, rel string) error
- func (c *Client) DeleteTemplate(ctx context.Context, sourcePath string) error
- func (c *Client) DuplicateNote(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (c *Client) EmptyTrash(ctx context.Context) error
- func (c *Client) Get(ctx context.Context, path string, out any) error
- func (c *Client) GetCurrentVault(ctx context.Context) (*vault.VaultInfo, error)
- func (c *Client) GetRaw(ctx context.Context, path string) ([]byte, error)
- func (c *Client) GetVaultSettings(ctx context.Context) (map[string]any, error)
- func (c *Client) ImportAsset(ctx context.Context, note, name string, body io.Reader) (vault.ImportedAsset, error)
- func (c *Client) ListAssets(ctx context.Context) ([]vault.AssetMeta, error)
- func (c *Client) ListFolders(ctx context.Context) ([]vault.FolderEntry, error)
- func (c *Client) ListNotes(ctx context.Context) ([]vault.NoteMeta, error)
- func (c *Client) ListTemplates(ctx context.Context) ([]vault.CustomTemplateFile, error)
- func (c *Client) MoveNote(ctx context.Context, rel string, folder vault.NoteFolder, subpath string) (vault.NoteMeta, error)
- func (c *Client) MoveToTrash(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (c *Client) Post(ctx context.Context, path string, body any, out any) error
- func (c *Client) ReadAsset(ctx context.Context, rel string) ([]byte, error)
- func (c *Client) ReadComments(ctx context.Context, rel string) ([]vault.NoteComment, error)
- func (c *Client) ReadNote(ctx context.Context, rel string) (vault.NoteContent, error)
- func (c *Client) ReadTemplate(ctx context.Context, sourcePath string) (string, error)
- func (c *Client) RenameFolder(ctx context.Context, folder vault.NoteFolder, oldSubpath, newSubpath string) (string, error)
- func (c *Client) RenameNote(ctx context.Context, rel, nextTitle string) (vault.NoteMeta, error)
- func (c *Client) RestoreFromTrash(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (c *Client) ScanTasks(ctx context.Context, includeExcluded bool) ([]vault.Task, error)
- func (c *Client) ScanTasksForPath(ctx context.Context, rel string, includeExcluded bool) ([]vault.Task, error)
- func (c *Client) SearchText(ctx context.Context, query string) ([]vault.TextSearchMatch, error)
- func (c *Client) SearchTextUpTo(ctx context.Context, query string, limit int) ([]vault.TextSearchMatch, error)
- func (c *Client) SetVaultSettings(ctx context.Context, settings map[string]any) (map[string]any, error)
- func (c *Client) UnarchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)
- func (c *Client) WatchChanges(ctx context.Context) (<-chan ChangeEvent, error)
- func (c *Client) WriteComments(ctx context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
- func (c *Client) WriteNote(ctx context.Context, rel, body string) (vault.NoteMeta, error)
- func (c *Client) WriteNoteIfUnchanged(ctx context.Context, rel, body, baseSha256 string) (vault.NoteMeta, error)
- func (c *Client) WriteTemplate(ctx context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
- type Header
- type NoteChangedError
- type RequestError
Constants ¶
const HeadersEnv = "ZENNOTES_REMOTE_HEADERS"
HeadersEnv is the variable zn, zn tui and zn mcp read the headers from.
const MaxHeaders = 20
MaxHeaders is more than any gateway needs; a pasted file is likelier.
Variables ¶
This section is empty.
Functions ¶
func ApplyHeaders ¶ added in v0.18.0
ApplyHeaders adds the headers to h. They never replace one already set.
func ConnectionErrorMessage ¶
ConnectionErrorMessage phrases a transport-level failure. On macOS a server on the local network needs the Local Network permission, and without it the attempt looks exactly like a server that is down.
func GatewayRefusedMessage ¶ added in v0.18.0
GatewayRefusedMessage names a gateway in front of the server that turned a request away. The ZenNotes server answers in plain text, so an HTML 403 came from something in front of it.
func IsNoteChanged ¶ added in v0.18.2
IsNoteChanged reports a write refused because the note moved on the server.
func IsSha256Hex ¶ added in v0.18.2
IsSha256Hex reports a value worth sending as a base: 64 hex digits.
func NormalizeBaseURL ¶
NormalizeBaseURL turns `localhost:7878` into `http://localhost:7878` and drops any trailing slash.
Types ¶
type AbsenceAwareReader ¶
type AbsenceAwareReader struct {
// contains filtered or unexported fields
}
AbsenceAwareReader tells "this file is absent" apart from "this request failed" against a server whose answer for the two might be the same.
Servers from 2.20 on answer 404 for a missing file and reserve 500 for real failures. Older ones answered 500 for both, and a client refusing to read 500 as absence cannot open a single database against one. Rather than guess from a version, the reader asks the server what it does: it requests a path that cannot exist and looks at the status, once per connection.
func NewAbsenceAwareReader ¶
func NewAbsenceAwareReader(read func(ctx context.Context, rel string) (string, error)) *AbsenceAwareReader
NewAbsenceAwareReader wraps a raw read.
func (*AbsenceAwareReader) ReadFileTextOrNull ¶
ReadFileTextOrNull returns nil for an absent file and an error for everything else.
type ChangeEvent ¶ added in v0.5.0
type ChangeEvent struct {
Kind string `json:"kind"`
Path string `json:"path"`
Scope string `json:"scope,omitempty"`
Err error `json:"-"`
}
ChangeEvent is the desktop/server watcher protocol.
type Client ¶
type Client struct {
BaseURL string
AuthToken string
// Headers go with every request and the change feed's handshake, for an
// access gateway in front of the server (see headers.go).
Headers []Header
// contains filtered or unexported fields
}
Client is a fetch-only client for one server.
func NewClient ¶
NewClient binds a client to a server and an optional token. It sends the extra headers from ZENNOTES_REMOTE_HEADERS; a value that does not parse fails every request with the reason, before anything is sent.
func NewClientWithTransport ¶ added in v0.17.0
func NewClientWithTransport(baseURL string, transport http.RoundTripper) *Client
NewClientWithTransport is a client whose requests go through transport instead of the network, for a server that calls its own API in-process. It sends no token: the transport is what vouches for the request.
func (*Client) ArchiveNote ¶
func (*Client) Capabilities ¶
Capabilities is what the server says it supports.
func (*Client) CreateFolder ¶
func (*Client) CreateNote ¶
func (*Client) DeleteFolder ¶
func (*Client) DeleteTemplate ¶
func (*Client) DuplicateNote ¶
func (*Client) GetCurrentVault ¶
GetCurrentVault is the vault the server is serving, or nil.
func (*Client) GetVaultSettings ¶
GetVaultSettings is the server's vault.json as it reports it.
func (*Client) ImportAsset ¶ added in v0.5.0
func (*Client) ListAssets ¶
func (*Client) ListFolders ¶
func (*Client) ListTemplates ¶
func (*Client) MoveToTrash ¶
func (*Client) ReadComments ¶
ReadComments loads a note's comment sidecar from the server.
func (*Client) ReadNote ¶
ReadNote carries the server's sha256 of the note in NoteMeta.Sha256 when the server sends one (supportsConditionalNoteWrites), for a later write's base.
func (*Client) ReadTemplate ¶
func (*Client) RenameFolder ¶
func (*Client) RenameNote ¶
func (*Client) RestoreFromTrash ¶
func (*Client) ScanTasksForPath ¶
func (*Client) SearchText ¶
func (*Client) SearchTextUpTo ¶ added in v0.17.0
func (c *Client) SearchTextUpTo(ctx context.Context, query string, limit int) ([]vault.TextSearchMatch, error)
SearchTextUpTo asks for more matches than a server returns by default, which only a current one honours. Zero takes its default.
func (*Client) SetVaultSettings ¶
func (c *Client) SetVaultSettings(ctx context.Context, settings map[string]any) (map[string]any, error)
SetVaultSettings writes the whole settings object back.
func (*Client) UnarchiveNote ¶
func (*Client) WatchChanges ¶ added in v0.5.0
func (c *Client) WatchChanges(ctx context.Context) (<-chan ChangeEvent, error)
func (*Client) WriteComments ¶
func (c *Client) WriteComments(ctx context.Context, rel string, comments []vault.NoteComment) ([]vault.NoteComment, error)
WriteComments replaces a note's comments on the server.
func (*Client) WriteNoteIfUnchanged ¶ added in v0.18.2
func (c *Client) WriteNoteIfUnchanged(ctx context.Context, rel, body, baseSha256 string) (vault.NoteMeta, error)
WriteNoteIfUnchanged writes a note only if it is still the version baseSha256 names: the sha256 a read or a write of it returned. A server with conditional writes refuses with 409 and writes nothing when the note changed or is gone since, which comes back as a *NoteChangedError. An empty base, or one that is not a hex SHA-256, sends none and the write is unconditional; an older server ignores the field, so it is only worth sending a value the server itself handed out.
func (*Client) WriteTemplate ¶
func (c *Client) WriteTemplate(ctx context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)
type Header ¶ added in v0.18.0
Header is one extra request header.
func EnvHeaders ¶ added in v0.18.0
EnvHeaders is HeadersFromEnv for this process, read once. A value that does not parse is an error every request returns before it is sent: running on without the headers would only trade this message for the gateway's 403.
func HeadersFromEnv ¶ added in v0.18.0
HeadersFromEnv reads HeadersEnv through getenv. Unset or blank means none. A JSON env block (an MCP client's config) can only carry a line break as the two characters `\n`, so those count as one.
func ParseHeaders ¶ added in v0.18.0
ParseHeaders reads `Name: value` lines. Blank lines and lines starting with `#` are skipped. The first problem wins and names its line; nothing is half-accepted.
type NoteChangedError ¶ added in v0.18.2
type NoteChangedError struct {
Path string
}
NoteChangedError is a write the server refused because the note is no longer the version the write named, or no longer exists. Nothing was written. The message is the desktop's, word for word.
func (*NoteChangedError) Error ¶ added in v0.18.2
func (e *NoteChangedError) Error() string
type RequestError ¶
RequestError is a non-2xx answer, with the status attached so a 404 (absent file) can be told from a real failure.
func (*RequestError) Error ¶
func (e *RequestError) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package remotetest is an in-memory ZenNotes server for tests: the note routes a read, change and write needs, with or without conditional note writes (znserver supportsConditionalNoteWrites).
|
Package remotetest is an in-memory ZenNotes server for tests: the note routes a read, change and write needs, with or without conditional note writes (znserver supportsConditionalNoteWrites). |