Documentation
¶
Overview ¶
Package ir is the binding-agnostic intermediate representation that sits between the AsyncAPI loader and the Go-source templates. The loader produces a *loader.Document that mirrors the YAML shape; the lowerer turns that into an *ir.Spec the templates iterate over.
Keeping the IR binding-agnostic at the top level (channels and operations) and per-binding only at the leaves (Channel.Binding) lets future bindings (Kafka, WebSocket) slot in without rewriting either the templates or the lowerer's spine. v1 ships only AMQP — see amqp.go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AMQPBinding ¶
type AMQPBinding struct {
// ChannelKind is the AsyncAPI `bindings.amqp.is` value. "routingKey"
// (publisher mode — address is the routing key on Exchange) or
// "queue" (consumer mode — address is the queue name; the queue is
// bound to Exchange separately). Empty when `bindings.amqp.is` is
// not declared (legacy v0.1.x specs imply routingKey for publishers).
ChannelKind string
// Exchange is the AMQP exchange name from `bindings.amqp.exchange.name`.
// Required for publishers; for consumer-mode channels it's the
// exchange the queue is bound to (informational).
Exchange string
// ExchangeType is "direct", "topic", "fanout", or "headers". From
// `bindings.amqp.exchange.type`.
ExchangeType string
// Queue is the consumer-side queue topology when ChannelKind == "queue"
// or when bindings.amqp.queue is declared. Nil for pure publisher
// channels (v0.1.x default).
Queue *AMQPQueue
// BindingVersion mirrors `bindings.amqp.bindingVersion`.
BindingVersion string
}
AMQPBinding is the typed view of an AsyncAPI channel's `bindings.amqp` stanza. v0.1.x captured only the publisher-relevant fields (exchange); v0.2 adds Queue + ChannelKind to drive subscriber emission.
type AMQPQueue ¶ added in v0.2.0
type AMQPQueue struct {
// Name is the queue name (may be a parameter template — see
// Channel.Address.Params for the typed parameter list).
Name string
// Durable / AutoDelete / Exclusive mirror the AsyncAPI fields.
// Defaults are zero-values (false) which matches the AsyncAPI
// default when the field is omitted.
Durable bool
AutoDelete bool
Exclusive bool
}
AMQPQueue mirrors `bindings.amqp.queue` for consumer-mode channels. When ChannelKind == "queue", Name is the same template as the channel address (the address IS the queue name in AsyncAPI 3.x queue mode); the field is preserved here so generated code can reference either.
type Action ¶ added in v0.2.0
type Action string
Action is the AsyncAPI operation.action value. Determines which template emits the operation: send → publisher, receive → subscriber.
const ( // ActionSend marks a publish operation. The publisher template emits // a Send<MessageName> method. ActionSend Action = "send" // ActionReceive marks a consume operation. The subscriber template // emits a <MessageName>Handler interface and a Subscribe<MessageName> // method (v0.2+). ActionReceive Action = "receive" )
type Address ¶
type Address struct {
// Raw is the original address string from the spec, used in
// generated-code comments so the reader can correlate to the YAML.
Raw string
// Parts is the address split on `{name}` boundaries, in order.
Parts []AddressPart
// Params is Parts filtered to just the parameter parts, in
// declaration order — the order publisher arguments appear in.
Params []AddressParam
}
Address is a parsed channel-address template. Templated parameters become Param parts; everything else is Literal.
func ParseAddress ¶
ParseAddress parses an AsyncAPI channel address template into an Address. Parameters use `{name}` syntax; everything else is literal.
Examples:
"widget.cancellation" → Parts: [Literal("widget.cancellation")]
"{tenant}.{widgetType}" → Parts: [Param("tenant"), Literal("."), Param("widgetType")]
"prefix.{a}.suffix.{b}" → Parts: [Literal("prefix."), Param("a"), Literal(".suffix."), Param("b")]
Nested braces and escaping are not supported — AsyncAPI 3.x doesn't define them. An unmatched `{` is an error.
func (Address) RoutingKeyExpr ¶
RoutingKeyExpr renders the Go expression that constructs the routing key from the parsed address. For all-literal addresses, returns a Go string literal ("widget.cancellation"). For templated addresses, returns a `+`-concatenation of arg names and quoted literals (a + "." + b). Single-parameter addresses become just the arg name.
type AddressParam ¶
type AddressParam struct {
// JSONName is the parameter name as it appears in the spec
// address template, e.g. "tenant".
JSONName string
// GoArgName is the Go function-argument name the publisher emits.
// Equal to JSONName today; reserved for future name-mangling
// (reserved-keyword escaping etc.).
GoArgName string
// GoType is the Go type emitted in the function signature; "string"
// for v1.
GoType string
}
AddressParam is a typed view of one channel-address parameter as it surfaces on the generated Publisher method signature. Today every parameter is `string`; future work can derive types from the AsyncAPI parameter schema.
type AddressPart ¶
type AddressPart struct {
// Literal is the raw text segment when this part is a literal,
// empty when it's a parameter.
Literal string
// Param is the parameter name when this part is a parameter,
// empty when it's a literal.
Param string
}
AddressPart is one segment of an address template. Either AddressLiteral or AddressParam — never both. (No interface to keep the template logic trivially branchable.)
func (AddressPart) IsParam ¶
func (p AddressPart) IsParam() bool
IsParam reports whether the part is a parameter reference.
type Binding ¶
type Binding interface {
// Kind returns the binding's protocol identifier ("amqp", future:
// "kafka", "ws"). Templates dispatch on this when more than one
// binding ships.
Kind() string
}
Binding is the marker interface for protocol-specific channel metadata. v1 has one implementation: *AMQPBinding (see amqp.go).
type Channel ¶
type Channel struct {
// Name is the AsyncAPI channel key, e.g. "widgetDispatch".
Name string
// Address is the parsed channel-address template.
Address Address
// Binding is the protocol-specific binding metadata. Concrete type
// is *AMQPBinding for v1; future bindings extend this interface.
Binding Binding
}
Channel is the AsyncAPI channel an operation publishes to.
type Message ¶
type Message struct {
// Name is the AsyncAPI message key, e.g. "WidgetMessage".
Name string
// GoTypeName is the exported Go struct type the payload generates
// to (matches the JSON Schema's `title`, since
// --struct-name-from-title is on).
GoTypeName string
}
Message is the resolved payload type the operation publishes.
type Operation ¶
type Operation struct {
// Name is the AsyncAPI operation key, e.g. "sendWidgetMessage" or
// "consumeWidgetMessage".
Name string
// Action is the operation's AsyncAPI action (send or receive).
Action Action
// GoFuncName is the exported Go method name. For send: "SendWidgetMessage"
// (on Publisher). For receive: "SubscribeWidgetMessage" (on Subscriber).
GoFuncName string
// HandlerTypeName is the interface name the subscriber generates and
// the consumer code implements. Only set for ActionReceive; empty for
// ActionSend. Form: <MessageName>Handler, e.g. "WidgetMessageHandler".
HandlerTypeName string
// HandlerMethodName is the single method on HandlerTypeName the
// consumer implements. Only set for ActionReceive. Form:
// Handle<MessageName>, e.g. "HandleWidgetMessage".
HandlerMethodName string
// Channel is the resolved channel this operation targets.
Channel *Channel
// Message is the resolved payload type.
Message *Message
// PublishDefaults carries AMQP message + operation binding values
// the publisher template wires into the default PublishProperties.
// Nil when the operation has no relevant bindings; the generated
// Send method still accepts SendOption opts but starts from a
// zero-value PublishProperties. v0.3+.
PublishDefaults *PublishDefaults
}
Operation is one published or consumed operation. Maps 1:1 to AsyncAPI `operations.X`. Action distinguishes publisher vs subscriber emission; everything else is shared.
type PublishDefaults ¶ added in v0.3.0
type PublishDefaults struct {
// ContentType from defaultContentType or messages.X.contentType.
// Always set when at least one of the spec sources declares it.
ContentType string
// ContentEncoding from messages.X.bindings.amqp.contentEncoding.
ContentEncoding string
// MessageType from messages.X.bindings.amqp.messageType.
MessageType string
// Priority from operations.X.bindings.amqp.priority (0-9 in AMQP).
Priority *uint8
// Expiration from operations.X.bindings.amqp.expiration. Per the
// AMQP wire format this is a string-encoded number of milliseconds;
// the IR keeps it as a string to preserve the spec author's exact
// declaration.
Expiration string
}
PublishDefaults holds the AMQP message-level + operation-level binding fields the publisher template materialises as default PublishProperties values. Each field is a pointer so the template can distinguish "spec didn't declare this" (nil → don't emit a default) from "spec declared zero" (non-nil → emit zero).
type Spec ¶
type Spec struct {
// PackageName is the Go package name the templates emit.
PackageName string
// DocTitle is doc.Info.Title, used in publisher comments.
DocTitle string
// Operations is the ordered list of operations to emit (only
// `action: send` operations in v1; `action: receive` is M3+).
Operations []*Operation
}
Spec is the root of the IR. One *Spec per generated Go package.