ir

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 3 Imported by: 1 module, 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

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.

func (*AMQPBinding) Kind

func (*AMQPBinding) Kind() string

Kind satisfies Binding.

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

func ParseAddress(s string) (Address, error)

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

func (a Address) RoutingKeyExpr() string

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
}

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 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.

Jump to

Keyboard shortcuts

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