genfile

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 8 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 genfile writes generated files for the local, endpoint and behavior generators alike: it removes the files a run made before, writes each file under the repository's root, and groups a Go file's imports as the repository does.

A Writer changes nothing on disk until Flush. Clean, Write, Go, Remove and Registry only record what to do, so a run that fails or panics part way, such as on a literal that jennifer cannot write, leaves the files of the last run as they were. Flush writes each file to a temporary file beside it and renames it, then removes the stale ones.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	Root string
	// contains filtered or unexported fields
}

Writer writes generated files under Root, a path relative to the working directory, such as ../../.. from a go:generate line. Call Flush when the whole run succeeds.

func (*Writer) Clean

func (w *Writer) Clean(
	dir string,
) error

Clean removes each file of dir that a generator made, by the comment that heads it, so a method or a group that is gone leaves nothing behind. A file that a person wrote stays.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush makes the changes that the run recorded: it writes each file, with the directories it needs, through a temporary file and a rename, then removes each stale file. Call it only when the whole run succeeded.

func (*Writer) Go

func (w *Writer) Go(
	rel string,
	f *jen.File,
) (err error)

Go renders f to rel, with its imports in the repository's three groups: the standard library, then other modules, then this one. That is all the format it gets: golangci-lint skips a generated file, so no check reads its format.

func (*Writer) Registry

func (w *Writer) Registry(
	dir string,
	header string,
	doc []string,
	pkgs []string,
) error

Registry is the file at dir/gen.go that imports each of pkgs for its init, so a binary registers each one with a single import, such as each endpoint group's routes. The file has header and the package comment doc.

func (*Writer) Remove

func (w *Writer) Remove(
	rel string,
) error

Remove records that Flush removes rel under the root, when it is there.

func (*Writer) Write

func (w *Writer) Write(
	rel string,
	data []byte,
) error

Write records data for rel under the root. Flush writes it.

Jump to

Keyboard shortcuts

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