gen

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 23 Imported by: 0 modules, 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 gen renders the code of a project from embedded templates. Most of the logic lives in the view types, which precompute code fragments so the templates stay readable.

Index

Constants

View Source
const (
	KubeBaseDir    = "deploy/kubernetes/base"
	KubeOverlayDir = "deploy/kubernetes/overlays/production"
)

Kubernetes manifests live in a generated kustomize base and a user-owned overlay. The base only references Secrets by name: codebuild never writes credentials, and the overlay is where images, namespaces and patches go.

View Source
const (
	ObservabilityDir     = "deploy/observability"
	KubeObservabilityDir = "deploy/kubernetes/components/observability"
	JaegerImage          = "jaegertracing/jaeger:2.21.0"
	PrometheusImage      = "prom/prometheus:v3.14.0"
	GrafanaImage         = "grafana/grafana:12.4.2"
)

The observability stack is generated next to the code: Jaeger with its Monitor tab fed by span metrics, Prometheus with alert rules, and Grafana with a dashboard of the project. Docker Compose runs it under the observability profile and Kubernetes gets it as a kustomize component. All three panels live under /_ops/, so the API or the gateway can put them behind the login of the project.

View Source
const (
	Header     = "// Code generated by codebuild. DO NOT EDIT."
	YAMLHeader = "# Code generated by codebuild. DO NOT EDIT."
)
View Source
const (
	GRPCModule      = "google.golang.org/grpc"
	GRPCVersion     = "v1.85.0"
	ProtobufModule  = "google.golang.org/protobuf"
	ProtobufVersion = "v1.36.12"
	GatewayDir      = "gateway"
	SharedDir       = "databases/shared"
)
View Source
const OpenAPIMarker = "Code generated by codebuild. DO NOT EDIT."

OpenAPIMarker is the value of the x-codebuild member that opens every generated openapi.json. JSON has no comments, so this member plays the role of the "Code generated" header that marks the file as codebuild's.

View Source
const OpenAPIPath = "openapi.json"

OpenAPIPath is where the document is written and served.

Variables

This section is empty.

Functions

func FormatGo

func FormatGo(src []byte) ([]byte, error)

func FormatGoModule

func FormatGoModule(src []byte, module string) ([]byte, error)

Templates import everything they might need. FormatGoModule drops the imports a file ends up not using, groups the rest the way goimports does and runs gofmt.

Types

type File

type File struct {
	Path          string
	Content       []byte
	Owner         Owner
	Domain        string
	ServiceType   string
	Receiver      string
	ServiceMethod string
	// ServiceSignature and ServiceParams describe the method the generated
	// code calls, so the planner can tell an outdated user method apart.
	ServiceSignature string
	ServiceParams    int
	Module           string
}

func Generate

func Generate(opts Options) ([]File, error)

type Module

type Module struct {
	Dir      string
	Path     string
	Requires [][2]string
	Locals   []string
}

type Options

type Options struct {
	Module        string
	GoVersion     string
	Caps          goversion.Capabilities
	Dialect       dialect.Dialect
	Model         *schema.Model
	Pagination    Pagination
	ManualWiring  []string
	HasMigrations bool
	Parts         Parts
}

type Owner

type Owner string
const (
	OwnerGenerated Owner = "generated"
	OwnerUser      Owner = "user"
)

type Pagination

type Pagination struct {
	DefaultLimit int `json:"defaultLimit"`
	MaxLimit     int `json:"maxLimit"`
}

type Parts added in v0.7.0

type Parts struct {
	Kubernetes    bool `json:"kubernetes"`
	Observability bool `json:"observability"`
	CI            bool `json:"ci"`
}

Parts are the optional outputs of a build. The code of the API is always generated; these deployment files can be left out of projects that do not use them.

func AllParts added in v0.7.0

func AllParts() Parts

type Workspace

type Workspace struct {
	Files   []File
	Modules []Module
}

func GenerateWorkspace

func GenerateWorkspace(opts WorkspaceOptions) (*Workspace, error)

type WorkspaceOptions

type WorkspaceOptions struct {
	Module     string
	GoVersion  string
	Caps       goversion.Capabilities
	Dialect    dialect.Dialect
	Model      *schema.Model
	Pagination Pagination
	Contracts  *contract.Set
	Migrations map[string]bool
	Parts      Parts
}

Jump to

Keyboard shortcuts

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