Releases: clipperhouse/gen
v4.3
This release includes a new -f
“force” flag. It allows gen to tolerate certain classes of type-check errors. Learn more…
v4.2
v4.1.1
Fix watch error behavior
v4.1
Added the watch
command, which automatically runs gen on file changes.
v4
From the changelog:
Type parameters
Tags now have support for type parameters, for example:
// +gen foo:"Bar[qux], Qaz[thing, stuff]"
type MyType struct{}
Those type parameters (qux, thing, stuff) are properly evaluated as types, and passed to your typewriters.
Type constraints
Speaking of above, types are evaluated for Numeric, Ordered and Comparable. Templates, in turn, can have type constraints.
For example, you can declare your Sum template only to be applicable to Numeric types, and your Set to Comparable types.
gen add
Third-party typewriters are added to your package using a new command, add
. It looks like this:
gen add github.com/clipperhouse/set
That’s a plain old Go import path.
After adding, you can mark up a type like:
// +gen set slice:"GroupBy[string], Select[Foo]"
type MyType struct{}
As always, it’s up to the third-party typewriter to determine behavior. In this case, a “naked” set
tag is enough.
We deprecated the unintuitive gen custom
command, add
replaces it.
Explcitness
Previous versions of gen would generate a dozen or so LINQ-style slice methods simply by marking up:
// +gen
type MyType struct{}
We’ve opted for explicitness moving forward – in the case of slices, you’ll write this instead:
// +gen slice:"Where, SortBy, Any"
type MyType struct{}
In other words, only the methods you want.
Projections
Certain methods, such as Select and GroupBy require an additional type parameter. I won’t bore you with the convoluted old way. Now it’s:
// +gen slice:"GroupBy[string], Select[Foo]"
type MyType struct{}
Those type parameters are properly evaluated, and typewriters get full type information on them.
slice
The main built-in typewriter used to be called genwriter
, it is now called slice
. Instead of the generated slice type being called Things, it’s now called ThingSlice.
slice is now the only built-in typewriter.
We’ve deprecated the built-in container typewriter, instead splitting it into optional Set, List and Ring typewriters.
You can add them using the add
command described above:
gen add github.com/clipperhouse/linkedlist
Smaller interface
For those developing their own typewriters: the TypeWriter
interface got smaller. It’s now:
type TypeWriter interface {
Name() string
Imports(t Type) []ImportSpec
Write(w io.Writer, t Type) error
}
Validate
is gone, it was awkward. The easy fix there was to allow Write to return an error. WriteHeader
is gone, there was little use for it in practice. WriteBody
is now simply Write
.
We also run goimports on generated code, so if your typewriter only uses the standard library, you might not need to specify anything for Imports() -- they’ll automagically be added to the generated source.
Let me (@clipperhouse) know if any questions.
v3.0.3
v3.0.2
A proper tag parser; API unchanged.
v3.0.1
Bug fixes