Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go 1.16 support for embedded files #51

Merged
merged 7 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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