Skip to content

Commit

Permalink
get rid of bindata, use embed
Browse files Browse the repository at this point in the history
  • Loading branch information
miku committed Jun 23, 2021
1 parent ee190d8 commit ebe36ce
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,24 @@ PKGNAME = span
.PHONY: all assets bench clean clean-docs cloc deb deps imports lint members names rpm test vet

# http://docs.travis-ci.com/user/languages/go/#Default-Test-Script
test: assets deps
test: deps
go get github.com/kylelemons/godebug/pretty
go get github.com/kr/pretty
go test ./...

all: assets deps $(TARGETS)

assets: assetutil/bindata.go

assetutil/bindata.go:
go generate
all: deps $(TARGETS)

deps:
go get -v ./...

$(TARGETS): %: cmd/%/main.go
go build -ldflags=-linkmode=external -o $@ $<
go build -ldflags="-w -s -linkmode=external" -o $@ $<

clean:
rm -f $(TARGETS)
rm -f $(PKGNAME)_*deb
rm -f $(PKGNAME)-*rpm
rm -rf ./packaging/deb/$(PKGNAME)/usr
rm -f assetutil/bindata.go

# Code quality and performance.
lint:
Expand Down
7 changes: 5 additions & 2 deletions assets.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:generate go get -u github.com/jteeuwen/go-bindata/...
//go:generate go-bindata -o assetutil/bindata.go -pkg assetutil assets/...
package span

import "embed"

//go:embed assets
var Static embed.FS
11 changes: 6 additions & 5 deletions assetutil/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"regexp"
"strings"

"github.com/miku/span"
"github.com/miku/span/container"
)

Expand Down Expand Up @@ -57,8 +58,8 @@ func (r RegexpMap) LookupDefault(s, def string) string {
// MustLoadRegexpMap loads the content of a given asset path into a RegexpMap. It
// will panic, if the asset path is not found and if the patterns found in the
// file cannot be compiled.
func MustLoadRegexpMap(ap string) RegexpMap {
b, err := Asset(ap)
func MustLoadRegexpMap(path string) RegexpMap {
b, err := span.Static.ReadFile(path)
if err != nil {
panic(err)
}
Expand All @@ -77,7 +78,7 @@ func MustLoadRegexpMap(ap string) RegexpMap {
func MustLoadStringSet(paths ...string) *container.StringSet {
s := container.NewStringSet()
for _, path := range paths {
b, err := Asset(path)
b, err := span.Static.ReadFile(path)
if err != nil {
panic(err)
}
Expand All @@ -104,7 +105,7 @@ func MustLoadStringSet(paths ...string) *container.StringSet {
// container.StringMap. This function will panic, if the asset cannot be found
// or the JSON is erroneous.
func MustLoadStringMap(path string) container.StringMap {
b, err := Asset(path)
b, err := span.Static.ReadFile(path)
if err != nil {
panic(err)
}
Expand All @@ -120,7 +121,7 @@ func MustLoadStringMap(path string) container.StringMap {
// a container.StringSliceMap. This function will halt the world, if it is
// called with an invalid argument.
func MustLoadStringSliceMap(path string) container.StringSliceMap {
b, err := Asset(path)
b, err := span.Static.ReadFile(path)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit ebe36ce

Please sign in to comment.