gogen

module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: BSD-3-Clause

README

gogen

Go Version License CI Go Reference TypeScript Reference Python Reference

gogen is a token-based source generation library for Go, TypeScript, TSX, and Python. Language adapters provide composable builders while shared internals handle reusable token rendering and layout.

Demo

Generate a formatted Go source file:

package main

import (
	"bytes"
	"fmt"

	gogen "go.osspkg.com/gogen/golang"
)

func main() {
	file := gogen.Package("main").Import("fmt", "fmt").Join(
		gogen.Func().ID("main").Bracket().Block(
			gogen.Pkg("fmt").ID("Println").Call(gogen.Text("hello, gogen")),
		),
	)

	var source bytes.Buffer
	if err := gogen.Render(&source, file); err != nil {
		panic(err)
	}
	fmt.Print(source.String())
}

Getting started

Requires Go 1.26 or newer:

go get go.osspkg.com/gogen/golang go.osspkg.com/gogen/typescript go.osspkg.com/gogen/python

Language guides

Language Package Guide
Go go.osspkg.com/gogen/golang Go builder guide
TypeScript and TSX go.osspkg.com/gogen/typescript TypeScript and TSX guide
Python 3.10+ go.osspkg.com/gogen/python Python guide

The Go adapter applies go/format by default. The TypeScript and Python adapters write readable source without invoking a formatter; use the language toolchain or a formatter separately when needed.

Contributing

See CONTRIBUTING.md for setup and local checks.

Contributors

Contributors

License

This project is licensed under the BSD 3-Clause License.

Directories

Path Synopsis
Package golang builds Go source from composable tokens.
Package golang builds Go source from composable tokens.
internal
gen
Package python builds Python 3.10+ source from composable tokens.
Package python builds Python 3.10+ source from composable tokens.
skills
Package types defines the public interfaces used by gogen tokens.
Package types defines the public interfaces used by gogen tokens.
Package typescript builds TypeScript and TSX source from composable tokens.
Package typescript builds TypeScript and TSX source from composable tokens.

Jump to

Keyboard shortcuts

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