eventgen

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineWithMetadata added in v0.3.5

func CombineWithMetadata(metadata *AvroSchema, payload *AvroSchema) ([]byte, error)

Combine creates an envelope schema JSON by combining metadata with payload.

func Generate added in v0.3.5

func Generate(cfg *Config) error

Generate generates all event-related code from Avro payload schemas.

func GenerateConstants added in v0.3.5

func GenerateConstants(cfg *Config, payloads []*AvroSchema) error

GenerateConstants generates the constants.gen.go file using jennifer.

func GenerateGoTypes added in v0.3.5

func GenerateGoTypes(cfg *Config, payloads []*AvroSchema) error

GenerateGoTypes uses hamba/avro/gen for payload types and jennifer for event wrappers.

func GenerateSchemaEmbeddings added in v0.3.5

func GenerateSchemaEmbeddings(cfg *Config, payloads []*AvroSchema) error

GenerateSchemaEmbeddings generates the schemas.gen.go file using jennifer.

func WriteSchemaFiles added in v0.3.5

func WriteSchemaFiles(cfg *Config, payloads []*AvroSchema) error

WriteSchemaFiles writes combined event schema files (metadata + payload) to the output directory.

Types

type AvroField

type AvroField struct {
	Name    string   `json:"name"`
	Type    any      `json:"type"` // Can be string, array, or object
	Doc     string   `json:"doc,omitempty"`
	Default any      `json:"default,omitempty"`
	Order   string   `json:"order,omitempty"`
	Aliases []string `json:"aliases,omitempty"`
}

AvroField represents a field in an Avro record.

type AvroSchema

type AvroSchema struct {
	Type      string      `json:"type"`
	Name      string      `json:"name"`
	Namespace string      `json:"namespace,omitempty"`
	Doc       string      `json:"doc,omitempty"`
	Topic     string      `json:"topic,omitempty"` // Kafka topic for this event
	Fields    []AvroField `json:"fields,omitempty"`
	Aliases   []string    `json:"aliases,omitempty"`
	Default   any         `json:"default,omitempty"`
}

AvroSchema represents a parsed Avro schema.

func ParseAvroSchema

func ParseAvroSchema(data []byte) (*AvroSchema, error)

ParseAvroSchema parses JSON bytes into an AvroSchema.

func ParsePayloads added in v0.3.5

func ParsePayloads(payloadsDir string) ([]*AvroSchema, error)

ParsePayloads reads and parses all *_payload.avsc files.

func (*AvroSchema) BaseName added in v0.3.5

func (s *AvroSchema) BaseName() string

BaseName returns the event name in snake_case (e.g., "product_created"). Used for schema file names.

func (*AvroSchema) EventName added in v0.3.5

func (s *AvroSchema) EventName() string

EventName returns the event name in PascalCase (e.g., "ProductCreated"). Derived from Name by removing "Payload" suffix.

func (*AvroSchema) EventSchemaFullName added in v0.3.5

func (s *AvroSchema) EventSchemaFullName() string

EventSchemaFullName returns the full qualified schema name for event (namespace.EventTypeName), e.g., "com.ecommerce.events.ProductCreatedEvent".

func (*AvroSchema) EventTypeName added in v0.3.5

func (s *AvroSchema) EventTypeName() string

EventTypeName returns the full event type name (e.g., "ProductCreatedEvent").

func (*AvroSchema) FullName

func (s *AvroSchema) FullName() string

FullName returns the fully qualified schema name (namespace.name).

func (*AvroSchema) PayloadTypeName added in v0.3.5

func (s *AvroSchema) PayloadTypeName() string

PayloadTypeName returns the payload type name (same as schema Name, e.g., "ProductCreatedPayload").

func (*AvroSchema) ToJSON

func (s *AvroSchema) ToJSON() ([]byte, error)

ToJSON converts the schema to formatted JSON bytes.

type Config

type Config struct {
	// PayloadsDir is the directory containing *_payload.avsc files.
	PayloadsDir string
	// OutputDir is the directory where generated code will be written.
	OutputDir string
	// Package is the Go package name for generated code. Defaults to "events".
	Package string
}

Config holds the configuration for the event generator.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the configuration is valid for generation.

Jump to

Keyboard shortcuts

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