remote

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 16 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func ConnectionErrorMessage

func ConnectionErrorMessage(baseURL string, err error) string

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 NormalizeBaseURL

func NormalizeBaseURL(value string) string

NormalizeBaseURL turns `localhost:7878` into `http://localhost:7878` and drops any trailing slash.

func StatusOf

func StatusOf(err error) int

StatusOf is the HTTP status behind an error, or 0 when it carries none.

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

func (r *AbsenceAwareReader) ReadFileTextOrNull(ctx context.Context, rel string) (*string, error)

ReadFileTextOrNull returns nil for an absent file and an error for everything else.

type Client

type Client struct {
	BaseURL   string
	AuthToken string
	// contains filtered or unexported fields
}

Client is a fetch-only client for one server.

func NewClient

func NewClient(baseURL, authToken string) *Client

NewClient binds a client to a server and an optional token.

func (*Client) ArchiveNote

func (c *Client) ArchiveNote(ctx context.Context, rel string) (vault.NoteMeta, error)

func (*Client) Capabilities

func (c *Client) Capabilities(ctx context.Context) (map[string]any, error)

Capabilities is what the server says it supports.

func (*Client) CreateFolder

func (c *Client) CreateFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error

func (*Client) CreateNote

func (c *Client) CreateNote(ctx context.Context, folder vault.NoteFolder, title, subpath string) (vault.NoteMeta, error)

func (*Client) DeleteFolder

func (c *Client) DeleteFolder(ctx context.Context, folder vault.NoteFolder, subpath string) error

func (*Client) DeleteNote

func (c *Client) DeleteNote(ctx context.Context, rel string) error

func (*Client) DeleteTemplate

func (c *Client) DeleteTemplate(ctx context.Context, sourcePath string) error

func (*Client) DuplicateNote

func (c *Client) DuplicateNote(ctx context.Context, rel string) (vault.NoteMeta, error)

func (*Client) EmptyTrash

func (c *Client) EmptyTrash(ctx context.Context) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, out any) error

Get performs a JSON GET.

func (*Client) GetCurrentVault

func (c *Client) GetCurrentVault(ctx context.Context) (*vault.VaultInfo, error)

GetCurrentVault is the vault the server is serving, or nil.

func (*Client) GetRaw

func (c *Client) GetRaw(ctx context.Context, path string) ([]byte, error)

GetRaw performs a GET and returns the body untouched.

func (*Client) GetVaultSettings

func (c *Client) GetVaultSettings(ctx context.Context) (map[string]any, error)

GetVaultSettings is the server's vault.json as it reports it.

func (*Client) ListAssets

func (c *Client) ListAssets(ctx context.Context) ([]vault.AssetMeta, error)

func (*Client) ListFolders

func (c *Client) ListFolders(ctx context.Context) ([]vault.FolderEntry, error)

func (*Client) ListNotes

func (c *Client) ListNotes(ctx context.Context) ([]vault.NoteMeta, error)

func (*Client) ListTemplates

func (c *Client) ListTemplates(ctx context.Context) ([]vault.CustomTemplateFile, error)

func (*Client) MoveNote

func (c *Client) MoveNote(ctx context.Context, rel string, folder vault.NoteFolder, subpath string) (vault.NoteMeta, error)

func (*Client) MoveToTrash

func (c *Client) MoveToTrash(ctx context.Context, rel string) (vault.NoteMeta, error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body any, out any) error

Post performs a JSON POST; a nil body sends `{}`.

func (*Client) ReadAsset

func (c *Client) ReadAsset(ctx context.Context, rel string) ([]byte, error)

ReadAsset fetches an attachment's bytes.

func (*Client) ReadComments

func (c *Client) ReadComments(ctx context.Context, rel string) ([]vault.NoteComment, error)

ReadComments loads a note's comment sidecar from the server.

func (*Client) ReadNote

func (c *Client) ReadNote(ctx context.Context, rel string) (vault.NoteContent, error)

func (*Client) ReadTemplate

func (c *Client) ReadTemplate(ctx context.Context, sourcePath string) (string, error)

func (*Client) RenameFolder

func (c *Client) RenameFolder(ctx context.Context, folder vault.NoteFolder, oldSubpath, newSubpath string) (string, error)

func (*Client) RenameNote

func (c *Client) RenameNote(ctx context.Context, rel, nextTitle string) (vault.NoteMeta, error)

func (*Client) RestoreFromTrash

func (c *Client) RestoreFromTrash(ctx context.Context, rel string) (vault.NoteMeta, error)

func (*Client) ScanTasks

func (c *Client) ScanTasks(ctx context.Context, includeExcluded bool) ([]vault.Task, error)

func (*Client) ScanTasksForPath

func (c *Client) ScanTasksForPath(ctx context.Context, rel string, includeExcluded bool) ([]vault.Task, error)

func (*Client) SearchText

func (c *Client) SearchText(ctx context.Context, query string) ([]vault.TextSearchMatch, error)

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 (c *Client) UnarchiveNote(ctx context.Context, rel string) (vault.NoteMeta, 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) WriteNote

func (c *Client) WriteNote(ctx context.Context, rel, body string) (vault.NoteMeta, error)

func (*Client) WriteTemplate

func (c *Client) WriteTemplate(ctx context.Context, input vault.WriteTemplateInput) (vault.CustomTemplateFile, error)

type RequestError

type RequestError struct {
	Status  int
	Message string
}

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

Jump to

Keyboard shortcuts

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