Help us shape the future of Go! Take the 2026 Go Developer Survey

modelgo

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: 10 Imported by: 0

Documentation

Overview

Package modelgo generates the model layer: the entity, its enums, its query types, and the inputs that change it.

It exists because the persistence layer and the API layer were each emitting their own copy of the same row, with a field-by-field conversion between them. Two definitions of one thing is two places to add a column and one place to forget, and the forgetting is silent — the field simply stops being returned.

So there is one definition, in a package both layers import, and no conversion at all. What each layer keeps is what only it can know: how a row is read and written, and how a request becomes one.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComparableField

func ComparableField(f ir.ResourceField) bool

ComparableField reports whether a column can be ordered.

func FilterFields

func FilterFields(fields []ir.ResourceField, keep func(ir.ResourceField) bool) []ir.ResourceField

FilterFields keeps the fields a predicate accepts.

It is exported because the persistence generator has to select exactly the same fields when it emits the code that renders a query — two answers to "which columns can be compared" would produce a struct field with nowhere to go.

func StringField

func StringField(f ir.ResourceField) bool

StringField reports whether a column can be matched against a pattern.

Types

type Generator

type Generator struct{}

Generator emits the model 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.
	Package string `json:"package"`
}

Options configure the generator.

Jump to

Keyboard shortcuts

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