vaultapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: BSD-2-Clause Imports: 10 Imported by: ? 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

Index

Constants

View Source
const (
	// FileReadKindList counts files read while listing a directory.
	FileReadKindList = "page_list"
	// FileReadKindRead counts files read by a single-page lookup.
	FileReadKindRead = "page_read"
)

File-read kinds. They are the label values of vault_api_file_reads_total and are bounded by construction, so the counter is pre-initialised for each.

Variables

This section is empty.

Functions

func NewCountingPageStorage

func NewCountingPageStorage(next storage.PageStorage, metrics Metrics) storage.PageStorage

NewCountingPageStorage wraps a PageStorage so every file it reads increments vault_api_file_reads_total. The index build is the only caller that reads files; query handlers serve from the index and never reach this decorator, which is what makes a flat counter across a query window meaningful.

func ResolveHead

func ResolveHead(vaultPath string) string

ResolveHead reads the commit the vault working tree currently points at, shortened to 8 characters. It reads .git/HEAD and the ref file directly so the service needs no git binary in its image. An empty string means the directory is not a git working tree (or the ref could not be read).

Types

type Config

type Config struct {
	VaultPath string
	VaultName string
	TasksDir  string
	GoalsDir  string
}

Config locates the vault working tree and the directories the index reads.

type GoalItem

type GoalItem struct {
	ID       string   `json:"id"`
	Title    string   `json:"title"`
	Path     string   `json:"path"`
	Status   string   `json:"status"`
	Themes   []string `json:"themes"`
	Assignee string   `json:"assignee,omitempty"`
	Vault    string   `json:"vault"`
}

GoalItem is the typed projection of one goal page. It is served by GET /api/v1/goals and GET /api/v1/goals/{id}.

type Index

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

Index is the in-memory view of the vault. It is rebuilt at startup and again whenever the working tree's HEAD changes, so list queries are map lookups rather than per-file reads.

func NewIndex

func NewIndex(cfg Config) *Index

NewIndex creates an empty index. Build populates it.

func (*Index) Build

func (i *Index) Build(ctx context.Context, store storage.PageStorage) error

Build reads every task and goal page and replaces the index atomically. A page whose frontmatter does not parse, or whose status/phase is present but not a known value, is excluded and counted in Warnings — never coerced.

func (*Index) GetGoal

func (i *Index) GetGoal(id string) (GoalItem, bool, string)

GetGoal resolves one goal by identifier or filename slug.

func (*Index) GetTask

func (i *Index) GetTask(id string) (TaskItem, bool, string)

GetTask resolves one task by identifier or filename slug. found is false when the id is absent; invalid carries the exclusion reason for a file that was refused rather than served.

func (*Index) Head

func (i *Index) Head() string

Head returns the working-tree commit the current index was built from.

func (*Index) QueryGoals

func (i *Index) QueryGoals() ([]GoalItem, int, int64)

QueryGoals returns every indexed goal, the warning count and the index age.

func (*Index) QueryTasks

func (i *Index) QueryTasks(filter TaskFilter) ([]TaskItem, int, int64)

QueryTasks returns the tasks matching filter, the current warning count and the index age in seconds.

func (*Index) Readiness

func (i *Index) Readiness() Readiness

Readiness reports whether the index is usable and how stale it is.

type ListResponse

type ListResponse[T any] struct {
	Items           []T   `json:"items"`
	Total           int   `json:"total"`
	Warnings        int   `json:"warnings"`
	IndexAgeSeconds int64 `json:"index_age_seconds"`
}

ListResponse is the envelope every list endpoint returns. Total is the number of items in the response; Warnings counts files excluded from the index because they could not be parsed or carry a value outside the enum.

type Metrics

type Metrics interface {
	AddFileReads(kind string, count int64)
}

Metrics is the instrumentation the storage decorator writes to.

func NewMetrics

func NewMetrics() Metrics

NewMetrics creates the service metrics and registers them. The file-read counter is pre-initialised with Add(0) so its series exists from boot — otherwise rate() is empty until the first read, and a counter diff taken across an index-served query window would be ambiguous.

type Readiness

type Readiness struct {
	Ready           bool   `json:"ready"`
	Vault           string `json:"vault"`
	IndexAgeSeconds int64  `json:"index_age_seconds"`
	Head            string `json:"head"`
	Warnings        int    `json:"warnings"`
}

Readiness is the body of GET /readiness.

type TaskFilter

type TaskFilter struct {
	Assignee string
	Status   string
	Phase    string
	Goal     string
	Cluster  string
}

TaskFilter narrows a task list. Empty fields are ignored; a query with no fields returns every indexed task.

type TaskItem

type TaskItem struct {
	ID       string   `json:"id"`
	Title    string   `json:"title"`
	Path     string   `json:"path"`
	Status   string   `json:"status"`
	Phase    string   `json:"phase"`
	Assignee string   `json:"assignee"`
	Goals    []string `json:"goals"`
	Cluster  *string  `json:"cluster"`
	Flag     bool     `json:"flag"`
	Vault    string   `json:"vault"`
}

TaskItem is the typed projection of one task page. It is served by GET /api/v1/tasks and GET /api/v1/tasks/{id}.

Directories

Path Synopsis
Package handler owns the HTTP surface: the five canonical admin endpoints and the typed /api/v1 read endpoints.
Package handler owns the HTTP surface: the five canonical admin endpoints and the typed /api/v1 read endpoints.

Jump to

Keyboard shortcuts

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