Skip to content

Releases: clipperhouse/gen

v4.3

15 Feb 19:05
Compare
Choose a tag to compare

This release includes a new -f “force” flag. It allows gen to tolerate certain classes of type-check errors. Learn more…

v4.2

04 Jan 21:24
Compare
Choose a tag to compare

Added stringer as a built-in typewriter.

v4.1.1

20 Dec 04:36
Compare
Choose a tag to compare

Fix watch error behavior

v4.1

14 Dec 20:19
Compare
Choose a tag to compare

Added the watch command, which automatically runs gen on file changes.

v4

30 Nov 18:30
Compare
Choose a tag to compare
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

10 Aug 15:59
Compare
Choose a tag to compare

Bug fix for pointers: b6ba7bc
Bug fix for ‘greater’ func: f5254a8
Feature: Go-style error messages with line number, etc: ed75c38

v3.0.2

04 Aug 03:56
Compare
Choose a tag to compare

A proper tag parser; API unchanged.

v3.0.1

07 Jul 03:40
Compare
Choose a tag to compare

Bug fixes

v3

29 Jun 04:18
Compare
Choose a tag to compare
v3

Support for _gen.go third-party typewriters has been added. See changelog.