Documentation
¶
Overview ¶
Package ant is the library behind the ant command line: a thin layer over a kit.Host that dereferences a resource URI to a record, regardless of which site it lives on.
ant owns no HTTP client and no per-site knowledge. Every domain it can address registers itself with kit from its own package's init, exactly as a database/sql driver does, and a program enables a domain with a single blank import:
import ( _ "github.com/tamnd/goodread-cli/goodread" _ "github.com/tamnd/x-cli/x" )
The Engine here is the sql.DB analogue: it opens the host once, then answers get/ls/links/resolve/url/export over the whole namespace.
Index ¶
- type DomainInfo
- type Engine
- func (e *Engine) Body(ctx context.Context, u kit.URI) (string, bool, error)
- func (e *Engine) BodyOf(env kit.Envelope) (string, bool)
- func (e *Engine) Domains() []DomainInfo
- func (e *Engine) Export(ctx context.Context, root kit.URI, follow int, asMarkdown bool) (*ExportReport, error)
- func (e *Engine) Get(ctx context.Context, u kit.URI) (kit.Envelope, error)
- func (e *Engine) Import(path string) (map[string]any, error)
- func (e *Engine) LL(prefix string) ([]string, error)
- func (e *Engine) Links(ctx context.Context, u kit.URI) ([]kit.URI, error)
- func (e *Engine) List(ctx context.Context, u kit.URI, limit int) ([]kit.Envelope, error)
- func (e *Engine) Resolve(input, on string) (kit.URI, error)
- func (e *Engine) Root() string
- func (e *Engine) URL(u kit.URI) (string, error)
- func (e *Engine) Walk(ctx context.Context, root kit.URI, depth int) (*Graph, error)
- type ExportReport
- type Graph
- type GraphEdge
- type GraphNode
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DomainInfo ¶
type DomainInfo struct {
Scheme string `json:"scheme"`
Aliases []string `json:"aliases,omitempty"`
Hosts []string `json:"hosts,omitempty"`
Binary string `json:"binary,omitempty"`
Short string `json:"short,omitempty"`
Site string `json:"site,omitempty"`
Repo string `json:"repo,omitempty"`
}
DomainInfo is one registered domain, as `ant domains` prints it.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine dereferences resource URIs across every registered domain and materializes them to the on-disk URI tree. It is safe for concurrent use; the underlying host builds each domain's client lazily on first touch.
func (*Engine) BodyOf ¶
BodyOf returns the long-text body of an already-fetched envelope's record, so `ant get -o md` need not fetch twice.
func (*Engine) Domains ¶
func (e *Engine) Domains() []DomainInfo
Domains returns the registered domains the Engine can address, sorted by scheme. It is the analogue of sql.Drivers and backs `ant domains`.
func (*Engine) Export ¶
func (e *Engine) Export(ctx context.Context, root kit.URI, follow int, asMarkdown bool) (*ExportReport, error)
Export materializes a URI's record to the data tree and, with follow > 0, walks its links to that depth, writing each record under its own URI path. It deduplicates by canonical URI so a cycle terminates, and reports every outcome rather than failing the whole walk on one bad node. asMarkdown also writes a .md body file for records that have one.
func (*Engine) Get ¶
Get dereferences a URI to its record, wrapped in the self-describing envelope (@id/@type/@fetched/@links) the data surface uses.
func (*Engine) Import ¶
Import reads an exported record file back into its envelope, the inverse of Export and the home of `ant import`.
func (*Engine) LL ¶
LL lists the record URIs already materialized on disk under a URI prefix. An empty prefix lists the whole tree. It is pure filesystem work, so it is fast and offline.
func (*Engine) List ¶
List returns the member records of a collection URI, each wrapped as an envelope. limit caps the result (0 means the op's own default).
func (*Engine) Resolve ¶
Resolve normalizes any input into a canonical URI. With on set, it resolves the input within that domain (the home of bare ids and @handles); otherwise it accepts a resource URI or a site URL whose host a domain claims.
type ExportReport ¶
type ExportReport struct {
Root string `json:"root"`
Written []string `json:"written"`
Skipped []string `json:"skipped,omitempty"`
Errors map[string]string `json:"errors,omitempty"`
}
ExportReport is the honest accounting of an export walk: what was written, what was already present, and which URIs failed (so a partial export never reads as a complete one).
type Graph ¶
Graph is the subgraph `ant graph` walks: every node reached within the depth and every edge between them.