servergo

package
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package servergo generates the HTTP layer: routing, decoding, and the registration struct.

Routes come straight from the document's precomputed patterns, so the router, the specification, and the client cannot disagree about a path. Registration goes through a struct with one field per resource, which makes forgetting to wire a new table a compile error rather than a 404 nobody notices until a client reports it.

A project with an `auth:` block gets one more file in the same package: the call that hands rig/auth exactly what that block says, so how long a token lives is a line in rig.yaml rather than a literal in a main function nobody diffs. The foundation itself is not generated — its endpoints, stores and hashing all live in the rig/auth module — and what is left in Go is what a configuration file cannot hold: a function, and a secret.

It is written here rather than by a generator of its own because it belongs to the same package: the error mapper it reaches for is this one's, so an authentication failure is shaped like every other failure without an import path in a configuration file to say where to find it. A project with no auth block gets no file at all, which is what keeps its API package — and its module — free of rig/auth.

Index

Constants

View Source
const DefaultRequestIDHeader = "X-Request-Id"

DefaultRequestIDHeader is where the generated error mapper looks for the identifier it puts in a failure body.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator struct{}

Generator emits the HTTP layer.

func New

func New() *Generator

New builds the generator.

func (*Generator) Description

func (*Generator) Description() string

Description implements gen.Generator.

func (*Generator) Generate

func (g *Generator) Generate(_ context.Context, doc *ir.Document, opts gen.Options) ([]gen.Artifact, error)

Generate implements gen.Generator.

func (*Generator) Name

func (*Generator) Name() string

Name implements gen.Generator.

func (*Generator) Version

func (*Generator) Version() string

Version implements gen.Generator.

type Options

type Options struct {
	// Package is the Go package the generated files declare. It is normally the
	// same package service-go writes into.
	Package string `json:"package"`
	// ModelImport is the import path of the generated model package, whose
	// input types the create and update handlers decode into.
	ModelImport string `json:"model_import"`

	// RequestIDHeader is the header the generated authentication error mapper
	// reads a request identifier from, so a failure from the sign-in endpoint
	// carries the same identifier as a failure from anywhere else.
	//
	// It only matters for a project with an auth block. Empty means
	// [DefaultRequestIDHeader].
	RequestIDHeader string `json:"request_id_header"`

	// ElectricURL is the sync service the shape endpoints proxy to. It becomes
	// the DefaultElectricURL a wiring can override, so a deployment can point at
	// a different one without regenerating.
	//
	// It only matters for a project where some table asked for live sync.
	ElectricURL string `json:"electric_url"`

	// ElectricRequired makes a sync service that is not answering a refusal to
	// start rather than a line in the log.
	//
	// False, the default, is a server that boots, says once that live sync is
	// not there, and serves — because that is what most projects want: a shape
	// with a fallback answers from the database, and every route that is not a
	// shape never touched the sync service at all.
	//
	// True is for the application whose pages are shapes, where starting is a
	// server that answers 502 to everything that matters. It also makes the sync
	// service part of the readiness check, so an instance that loses it is taken
	// out of the load balancer rather than left in it answering nothing.
	//
	// It only matters for a project where some table asked for live sync.
	ElectricRequired bool `json:"electric_required"`

	// StubDir is where the hand-owned shape scoping files go, relative to the
	// project root. {table} and {Table} are substituted. Empty writes no stubs.
	//
	// The same directory service-go writes its service stub into: everything
	// about one table in one place.
	StubDir string `json:"stub_dir"`
	// StubPackage names the package a shape stub declares. Empty uses the table
	// name.
	StubPackage string `json:"stub_package"`
	// APIImport is the import path of this generated package, so a shape stub in
	// another directory can name the scope type it satisfies.
	APIImport string `json:"api_import"`
}

Options configure the generator.

Jump to

Keyboard shortcuts

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