layout

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package layout places generated parts in files and gives each folder its package name and import path.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownSelector  = errors.New("unknown selector")
	ErrSelectorConflict = errors.New("selector conflict")
	ErrNoModule         = errors.New("no module path")
	ErrOutsideModule    = errors.New("outside the module")
	ErrImportCycle      = errors.New("import cycle")
	ErrModule           = errors.New("read go.mod")
	ErrPackageConflict  = errors.New("two packages in one folder")
	ErrSplitParts       = errors.New("parts that belong together are in different folders")
)

Functions

This section is empty.

Types

type File

type File struct {
	Path       string
	Rel        string
	Package    string
	ImportPath string
	Parts      []PartID
	Kind       FileKind
}

File is one output file. Path is resolved against the config folder; Rel is the path as the config writes it. Parts keep the order the generators gave.

type FileKind

type FileKind int
const (
	Generated FileKind = iota
	Scaffold
)

type Layout

type Layout struct {
	Files   []*File
	Package string
	// contains filtered or unexported fields
}

Layout holds the files that got at least one part, sorted by path. Package is the package of output.file, which is not among them when every part went elsewhere.

func Plan

func Plan(cfg *config.Config, parts []Part, mod Module) (*Layout, error)

Plan puts every part in the file whose selector matches it most closely, output.file when none does, then names the package and import path of every folder.

func (*Layout) CheckImports

func (l *Layout) CheckImports(imports map[PartID][]string) error

CheckImports fails when the folders import each other in a cycle through what the parts wrote, which Plan cannot see for the code of an extra file. imports lists, by part, the import paths its file held once the part was written, so a path counts for the first part of a file that has it.

func (*Layout) FileOf

func (l *Layout) FileOf(p PartID) *File

FileOf returns the file that holds p, or nil for a part the layout does not know.

type Module

type Module struct {
	Path string
	Dir  string
}

Module is the Go module the output belongs to. Path is empty when none is known.

func FindModule

func FindModule(dir, override string) (Module, error)

FindModule reads the nearest go.mod in dir or above it. A non-empty override replaces its module path; without a go.mod, the module is override rooted at dir.

type Part

type Part struct {
	ID      PartID
	Uses    []PartID
	Package string
	Owner   PartID
	Reason  string
}

Part is a part a generator writes, with the parts its code refers to. Package, when set, is the package name of the file that holds it, whatever its folder is called: main for a program. Owner, when set, is the part whose folder this one must share, and Reason says why, after the ID.

type PartID

type PartID string

PartID names one piece of generated code, such as models.types.

const (
	PartScaffoldService    PartID = "server.scaffold.service"
	PartScaffoldMiddleware PartID = "server.scaffold.middleware"
	PartScaffoldMain       PartID = "server.scaffold.main"
)

The parts of the scaffold files, each written to the file the config names for it.

Jump to

Keyboard shortcuts

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