generator

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package generator turns WIT contracts into Go bindings.

Index

Constants

View Source
const DefaultFilename = "bindings.gen.go"

Variables

This section is empty.

Functions

func Generate

func Generate(config Config) error

func Render

func Render(file *ir.File, packageName string) ([]byte, error)

Render converts a lowered WIT file into unformatted Go source.

func RenderWithOptions

func RenderWithOptions(file *ir.File, packageName string, options RenderOptions) ([]byte, error)

Types

type Config

type Config struct {
	WIT              string
	WITFiles         []string
	WITMode          InputMode
	GoOverlay        string
	Output           string
	Package          string
	Filename         string
	EnableRuntimeAPI bool
	Mode             GenerationMode
	World            string
	PackageRoot      string
	GuestBindgen     string
}

type GenerationMode added in v1.1.0

type GenerationMode uint8
const (
	GenerateHost GenerationMode = iota
	GenerateGuest
)

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

func New

func New(config Config) (*Generator, error)

func (*Generator) Generate

func (g *Generator) Generate() error

type GoErrorMapping

type GoErrorMapping struct {
	ResultError bool `yaml:"result_error"`
}

GoErrorMapping maps a WIT result return to idiomatic Go error returns.

type GoOverlay

type GoOverlay struct {
	Version int                       `yaml:"version"`
	Types   map[string]GoTypeMapping  `yaml:"types"`
	Errors  map[string]GoErrorMapping `yaml:"errors"`
	// contains filtered or unexported fields
}

GoOverlay describes optional public Go representations over canonical WIT wire types. It is resolved and validated before rendering.

func LoadGoOverlay

func LoadGoOverlay(filename string, file *ir.File) (*GoOverlay, error)

LoadGoOverlay reads and validates a version 1 overlay. An empty path disables overlays and preserves historical generation exactly.

type GoTypeMapping

type GoTypeMapping struct {
	GoType string `yaml:"go_type"`
	Import string `yaml:"import"`
	Codec  string `yaml:"codec"`
}

GoTypeMapping maps one canonical WIT alias to a public Go type.

type InputMode

type InputMode uint8

InputMode controls expansion of a WIT source path.

const (
	InputAuto InputMode = iota
	InputFile
	InputPackage
	InputTree
)

type RenderOptions

type RenderOptions struct {
	EnableRuntimeAPI bool
	GoOverlay        *GoOverlay
}

Jump to

Keyboard shortcuts

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