On this page
Reading the authoring app's hand-written TOML registry of the repositories it may open, strictly: every key known, every name unique, every path real.
#internal/blog/editor/registry
#internal/blog/editor/registry
Package registry reads the authoring app's repository registry: a hand-written TOML file.
This is not framework configuration. It is one machine-local list of the repositories the editor may open, written by hand by the one person the editor serves, and read strictly: every key is known, every required key is present, every name is unique and addressable in a URL, and every local path really is a directory. Anything else refuses and names the offender.
The strictness is the point. A registry entry that quietly fails to parse is a project whose posts silently stop being editable, with no error anywhere to explain why -- so there is no shape here that is merely skipped.
#Format
Two kinds of entry, both under [[repo]], both declaring their kind:
[[repo]] name = "selfdoc" kind = "local" path = "~/Projects/selfdoc"
[[repo]] name = "afar" kind = "remote" repo = "smm-h/afar" ref = "v1.2.3" cache = "~/.cache/selfdoc/afar" render = true
A remote entry is validated in full but not served yet: the server refuses it with "remote entries not yet served" rather than pretending. render is required and has no default because directive resolution reads a source tree, and whether a remote entry gets one is a decision the file has to state.
#Error
type Error structError reports that the registry file is unusable, and the message says exactly how.
It is the Go counterpart of the Python surface's RegistryError, and the one error type a caller needs to recognize with errors.As to render a registry refusal as one line instead of an unexpected internal failure.
#Entry
type Entry interfaceEntry is one registry entry: a [LocalRepo] or a [RemoteRepo]. The two are separate types rather than one struct with unused members because the server serves a local entry and refuses a remote one, and the distinction is the thing it branches on.
#LocalRepo
type LocalRepo structLocalRepo is a working tree on this machine. Edits land in it directly.
#RemoteRepo
type RemoteRepo structRemoteRepo is a repository elsewhere. Validated here, not served yet.
#Registry
type Registry structRegistry is the parsed registry: ordered entries, addressable by name.
#DefaultPath
func DefaultPath() stringDefaultPath returns where the registry lives. Machine-local by design -- the editor writes working trees on this machine and is not a published, shared surface, so its list of repositories belongs beside the other machine-local records rather than in any project's committed config.
It is a function rather than a constant because it reads the home directory out of the environment, which the Python module it replaces did once at import time.
#Load
func Load(path string) (*Registry, error)Load reads and validates the registry at path. An empty path reads [DefaultPath].
It returns an [Error] when the file is missing, unparsable, or declares any shape this package does not accept. The message names the offender.
#Error.Error
func (e *Error) Error() string { return e.Message }Error returns the diagnostic.
#LocalRepo.Name
func (r *LocalRepo) Name() string { return r.name }Name is the entry's registry name.
#LocalRepo.Kind
func (r *LocalRepo) Kind() string { return "local" }Kind is "local".
#LocalRepo.Path
func (r *LocalRepo) Path() string { return r.path }Path is the absolute path of the working tree.
#RemoteRepo.Name
func (r *RemoteRepo) Name() string { return r.name }Name is the entry's registry name.
#RemoteRepo.Kind
func (r *RemoteRepo) Kind() string { return "remote" }Kind is "remote".
#RemoteRepo.Repo
func (r *RemoteRepo) Repo() string { return r.repo }Repo is the repository the entry names, as owner/name.
#RemoteRepo.Ref
func (r *RemoteRepo) Ref() string { return r.ref }Ref is the git ref the entry pins.
#RemoteRepo.Cache
func (r *RemoteRepo) Cache() string { return r.cache }Cache is the absolute path of the checkout cache.
#RemoteRepo.Render
func (r *RemoteRepo) Render() bool { return r.render }Render states whether rendering runs against a checkout: directive resolution needs a source tree, so an entry that answers no can only ever serve prose. It is required in the file because neither answer is safe to assume.
#Registry.Names
func (r *Registry) Names() []stringNames returns the entry names, in the order the file declares them.
#Registry.Get
func (r *Registry) Get(name string) (Entry, error)Get returns the entry called name, or a refusal naming what is on offer.
#Registry.Len
func (r *Registry) Len() int { return len(r.Entries) }Len returns how many entries the registry declares.
#Registry.RenderList
func (r *Registry) RenderList() []stringRenderList returns the lines editor list-repos prints: one per entry -- a local entry's working tree, or a remote entry's repository, ref and whether it declares that rendering runs against a checkout -- then a blank line and the count. An empty registry renders as the one line that says so.