Documentation
¶
Overview ¶
Package goapiuse is part of the CivNode Training semantic engine.
It loads an offline index of dominant call patterns ("shapes") for Go stdlib and popular third-party APIs. The index is built offline by the companion cmd/go-apiuse-ingest tool and consumed at runtime by Training to show "used in production" sidebars and hover popovers.
See https://github.com/CivNode/go-apiuse for details.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EncodePublic ¶
func EncodePublic(w io.Writer, art ArtifactV1) error
EncodePublic writes an artifact to w. It is the stable entry point the ingest command uses to serialise the corpus result. External callers outside the CivNode Training toolchain should not rely on this; the gob format may evolve between artifact schema versions.
func ExtractShape ¶
func ExtractShape(sc ShapeContext) string
ExtractShape returns a canonical, compact string describing the call. The goal is aggressive clustering: a corpus of 10 real-world calls to a given API should collapse to 3 or fewer shapes.
The shape encodes three facts:
- the call's syntactic context (assignment arity, return statement, argument position, bare statement, ...);
- the argument count;
- for each argument, a compact category (identifier, literal, call, selector, duration-like, ...).
Identifier names are deliberately discarded. Package-qualified selectors keep the selector path because it is often semantically load-bearing (e.g. time.Second vs http.StatusOK).
func ResolveCallee ¶
ResolveCallee returns the fully-qualified name of the callee in call, or the empty string if the callee cannot be resolved (e.g. an unresolved function literal or a dynamic dispatch through an interface with no type information available).
The returned form is:
pkg/path.FuncName for package-level functions and constructors pkg/path.TypeName.Method for methods on named types (pointer or not) (builtin).FuncName for Go built-ins like len, cap, make
Only the latter two use a period separator between receiver and method to stay compatible with the string keys the ingest tool emits.
Types ¶
type ArtifactV1 ¶
ArtifactV1 is the on-disk layout, gob-encoded. A nested struct means future fields can be added without breaking older consumers as long as we only ever add new trailing fields. Exported so the ingest command in cmd/go-apiuse-ingest can construct it directly without duplicating the definition.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is an opaque handle over a loaded artifact. Safe for concurrent reads once Load / LoadFromFS has returned.
func Load ¶
Load reads an index from the filesystem. It is a thin wrapper over LoadFromFS using os.DirFS on the parent directory.
func LoadFromFS ¶
LoadFromFS reads an index from an fs.FS. This is the preferred form when the artifact is shipped via embed.FS.
type Meta ¶
type Meta struct {
Version int // artifact schema version; current = 1
BuiltAt string // RFC3339 timestamp
Source string // free-form description of the corpus
CallCount int // total number of resolved calls ingested
}
Meta describes the artifact that was loaded. Stored as the first value in the gob stream so that older consumers can still read the entries map.
type ShapeContext ¶
type ShapeContext struct {
Call *ast.CallExpr
Parent ast.Node // immediate parent of Call in the AST walk
// Info is the type-checked info produced by go/packages. Must include
// Types + Uses + Defs. A nil Info means "types not available"; the
// shape will fall back to syntactic classification.
Info *types.Info
}
ShapeContext is what the ingest tool feeds into ExtractShape. It carries everything the shape extractor needs to decide on a canonical string without holding a reference to a types.Package.
type Usage ¶
type Usage struct {
// Pattern is a canonical, compact description of the call shape. For
// example: "two-result assign, 2 args, arg[1] is duration literal".
Pattern string
// Frequency is the fraction (0..1) of all observed calls to the API
// that match this shape. A value of 1.0 means every call in the
// corpus used this shape.
Frequency float64
// ExampleRepos lists up to five source locations (repo or file paths)
// where the shape was observed. Purely informational.
ExampleRepos []string
}
Usage is one call-shape entry for a given fully-qualified API name.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
go-apiuse-ingest
command
go-apiuse-ingest walks one or more Go source trees, resolves the callee of every function call, extracts a canonical call-shape for each, and writes a gob-encoded index.bin suitable for consumption by the goapiuse runtime library.
|
go-apiuse-ingest walks one or more Go source trees, resolves the callee of every function call, extracts a canonical call-shape for each, and writes a gob-encoded index.bin suitable for consumption by the goapiuse runtime library. |