Documentation
¶
Overview ¶
Package codegen reads a schema-registry snapshot and emits typed Go and TypeScript bindings for each registered ChannelPattern.
The output supports two use cases:
- Go publishers and subscribers that want strongly-typed payloads via client.OnAspectTyped[T any] without writing the structs by hand.
- TypeScript browser clients that want compile-time guarantees on envelope payloads and channel names.
The generator is deliberately small: a hand-written walker over schema.JSONSchema (the subset already shipped in the schema package) driven by a tiny template. It does not pull a full JSON-Schema compiler — anything richer than the supported subset is emitted as json.RawMessage / unknown so the consumer can extend later without fork.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generators ¶
Generators returns the registered generators by name. Adding a new language means registering a new Generator implementation here.
Types ¶
type Generator ¶
type Generator interface {
Name() string
Generate(snap schema.Snapshot, opts Options) ([]byte, error)
}
Generator is the language-specific code emitter. Implementations produce a single self-contained file.
type GoGenerator ¶
type GoGenerator struct{}
GoGenerator emits a single self-contained Go file.
type Options ¶
type Options struct {
// Package is the Go package name to emit. Defaults to "parsecgen".
// Ignored when the target language is TypeScript.
Package string
// Header is prepended verbatim above the generator's own header.
// Use for project-specific build tags or license stanzas.
Header string
}
Options controls a generation run.
type Source ¶
type Source struct {
URL string
File string
Client *http.Client // optional override; defaults to http.DefaultClient with a 30s timeout
}
Source is where the generator loads a snapshot from.
Exactly one of URL or File must be set. The URL form fetches the JSON returned by schema.Handler at the configured prefix; the File form reads a snapshot previously written to disk (typically by piping the HTTP response through `jq` and committing it).
type TSGenerator ¶
type TSGenerator struct{}
TSGenerator emits a single self-contained TypeScript file.