generation

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 38 Imported by: 0

Documentation

Overview

Package generation provides tools for generating resource-driven API boilerplate in Go & TypeScript based on Go structures and a Spanner DB schema.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileWriter added in v0.1.14

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

FileWriter provides convenience methods to safely goformat & write bytes to file.

func (*FileWriter) GoFormatBytes added in v0.1.14

func (f *FileWriter) GoFormatBytes(fileName string, data []byte) ([]byte, error)

GoFormatBytes runs Go Format on bytes for a go source file. If the Go source data is not syntactically correct, GoFormatBytes will return an error. Safe to use concurrently.

func (*FileWriter) WriteBytesToFile added in v0.1.14

func (f *FileWriter) WriteBytesToFile(file *os.File, data []byte) error

WriteBytesToFile truncates a file and writes given bytes to it.

type Generator added in v0.0.16

type Generator interface {
	Generate() error
	Close() error
}

Generator provides methods for generating Go or Typescript for a resource-driven web application.

func NewResourceGenerator added in v0.0.14

func NewResourceGenerator(ctx context.Context, resourceSourcePath, migrationSourceURL string, localPackages []string, options ...ResourceOption) (Generator, error)

NewResourceGenerator constructs a new Generator for generating a resource-driven API.

func NewTypescriptGenerator added in v0.0.14

func NewTypescriptGenerator(ctx context.Context, resourceSourcePath, migrationSourceURL, targetDir string, rc *resource.Collection, options ...TSOption) (Generator, error)

NewTypescriptGenerator constructs a new Generator for generating Typescript for a resource-driven Angular app.

type HandlerType

type HandlerType string

HandlerType describes the possible handlers implemented in a resource-driven API.

const (
	// AllHandlers is create, update, read, delete, and list handlers.
	AllHandlers HandlerType = "allHandlers"
	// ListHandler is the list handler.
	ListHandler HandlerType = "listHandler"
	// ReadHandler is the read handler.
	ReadHandler HandlerType = "readHandler"
	// PatchHandler is the patch handler.
	PatchHandler HandlerType = "patchHandler"
)

type Option added in v0.0.16

type Option func(any) error

Option is a functional option for configuring a Generator

func CaserInitialismOverrides added in v0.0.10

func CaserInitialismOverrides(overrides map[string]bool) Option

CaserInitialismOverrides sets the initialism for any resources that are not covered by the default initialisms.

func WithConsolidatedHandlers added in v0.0.13

func WithConsolidatedHandlers(route string, consolidateAll bool, resources ...string) Option

WithConsolidatedHandlers enables generating a handler file for all or a list of resources.

func WithPluralOverrides added in v0.0.10

func WithPluralOverrides(overrides map[string]string) Option

WithPluralOverrides sets the pluralization for any resources that are not covered by the default pluralizations.

func WithRPC added in v0.0.16

func WithRPC(rpcPackageDir string) Option

WithRPC enables generating RPC method handlers.

func WithSpannerEmulatorVersion added in v0.1.18

func WithSpannerEmulatorVersion(version string) Option

WithSpannerEmulatorVersion sets the version of the Spanner image pulled from gcr.io

type ResourceOption added in v0.0.14

type ResourceOption interface {
	// contains filtered or unexported methods
}

ResourceOption is a functional option for configuring a ResourceGenerator

func GenerateHandlers added in v0.0.10

func GenerateHandlers(targetDir string) ResourceOption

GenerateHandlers enables generating a handler file for each resource. To generate resource handlers in a single file use WithConsolidatedHandlers.

func GenerateRoutes added in v0.0.13

func GenerateRoutes(targetDir, targetPackage, routePrefix string) ResourceOption

GenerateRoutes enables generating a router file containing routes for all handlers and RPC methods.

type TSOption added in v0.0.14

type TSOption interface {
	// contains filtered or unexported methods
}

TSOption is a functional option for configuring a TypescriptGenerator

func GenerateEnums added in v0.2.21

func GenerateEnums() TSOption

GenerateEnums enables generating constants for resources that have been tagged with `@enumerate` and have Id and Description values in the schema migrations directory.

func GenerateMetadata added in v0.2.21

func GenerateMetadata() TSOption

GenerateMetadata enables generating information necessary for Typescript configuration of resources.

func GeneratePermissions added in v0.2.21

func GeneratePermissions() TSOption

GeneratePermissions enables generating resource and resource-field level permission mappings, based on the routes registered in the app router. Requires `collect_resource_permissions` build tag.

func WithTypescriptOverrides added in v0.0.13

func WithTypescriptOverrides(overrides map[string]string) TSOption

WithTypescriptOverrides sets the Typescript type for a given Go type.

Directories

Path Synopsis
Package parser is a simplified abstraction over go/parser, tailored for the go:generate resource/generation tool.
Package parser is a simplified abstraction over go/parser, tailored for the go:generate resource/generation tool.
genlang
Package genlang provides parsing for godoc comment annotations
Package genlang provides parsing for godoc comment annotations

Jump to

Keyboard shortcuts

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