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 ¶
- type Writer
- func (w *Writer) Clean(dir string) error
- func (w *Writer) Flush() error
- func (w *Writer) Go(rel string, f *jen.File) (err error)
- func (w *Writer) Registry(dir string, header string, doc []string, pkgs []string) error
- func (w *Writer) Remove(rel string) error
- func (w *Writer) Write(rel string, data []byte) error
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 ¶
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 ¶
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 ¶
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 ¶
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.