Skip to content

Commit

Permalink
Go 1.16 support for embedded files (#51)
Browse files Browse the repository at this point in the history
* add go 1.16
  • Loading branch information
abice authored Jul 5, 2021
1 parent e81b720 commit b593b64
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
docker:
- image: circleci/golang:1.15
<<: *common_parts
golang_1.16:
docker:
- image: circleci/golang:1.16
<<: *common_parts

workflows:
version: 2
Expand All @@ -45,3 +49,4 @@ workflows:
- golang_1.13
- golang_1.14
- golang_1.15
- golang_1.16
16 changes: 16 additions & 0 deletions generator/embedded.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:generate ../bin/go-bindata -nometadata -o assets/assets.go -pkg=assets enum.tmpl
// +build !go1.16

package generator

import (
"text/template"

"github.com/abice/go-enum/generator/assets"
)

func (g *Generator) addEmbeddedTemplates() {
for _, asset := range assets.AssetNames() {
g.t = template.Must(g.t.Parse(string(assets.MustAsset(asset))))
}
}
15 changes: 15 additions & 0 deletions generator/embedded_1.16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build go1.16

package generator

import (
"embed"
"text/template"
)

//go:embed enum.tmpl
var content embed.FS

func (g *Generator) addEmbeddedTemplates() {
g.t = template.Must(g.t.ParseFS(content, "*.tmpl"))
}
7 changes: 1 addition & 6 deletions generator/generator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:generate ../bin/go-bindata -nometadata -o assets/assets.go -pkg=assets enum.tmpl

package generator

import (
Expand All @@ -16,7 +14,6 @@ import (
"unicode"

"github.com/Masterminds/sprig"
"github.com/abice/go-enum/generator/assets"
"github.com/pkg/errors"
"golang.org/x/tools/imports"
)
Expand Down Expand Up @@ -83,9 +80,7 @@ func NewGenerator() *Generator {

g.t.Funcs(funcs)

for _, asset := range assets.AssetNames() {
g.t = template.Must(g.t.Parse(string(assets.MustAsset(asset))))
}
g.addEmbeddedTemplates()

g.updateTemplates()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/abice/go-enum

go 1.12
go 1.16

require (
github.com/Masterminds/goutils v1.1.0 // indirect
Expand Down

0 comments on commit b593b64

Please sign in to comment.