Skip to content

Commit

Permalink
Use embed instead of go-bindata
Browse files Browse the repository at this point in the history
  • Loading branch information
xaxys committed Apr 11, 2022
1 parent 05beaa6 commit 8239e30
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 268 deletions.
3 changes: 0 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ before:
hooks:
- go mod tidy
- go generate ./...
# install and run go-bindata
- go install -a github.com/go-bindata/go-bindata/...@latest
- go-bindata -nomemcopy --pkg bindata -o ./bindata/bindata.go fonts/...
builds:
- id: darwin_amd64
env:
Expand Down
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ endif

all: build

build: bindata
build:
@echo "Building MaintainMan ..."
@$(GO) env -w CGO_ENABLED="1"
@$(GO) build \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-o $(TARGET) $(PWD)/main.go

test: clean bindata
test: clean
@echo "Testing MaintainMan ..."
@$(GO) env -w CGO_ENABLED="1"
@$(GO) test \
-ldflags="-X 'main.BuildTags=$(BUILD_TAGS)' -X 'main.BuildTime=$(BUILD_TIME)' -X 'main.GitCommit=$(GIT_COMMIT)' -X 'main.GoVersion=$(GO_VERSION)'" \
-timeout=30m -coverprofile=coverage.out ./...

bindata:
@echo "Run go-bindata ..."
@$(GO) install -a github.com/go-bindata/go-bindata/...@latest
@go-bindata -nomemcopy --pkg bindata -o ./bindata/bindata.go fonts/...

clean:
@echo "Cleaning MaintainMan ..."
@$(RM_CMD_1) $(TARGET) $(RM_CMD_2)
Expand All @@ -57,4 +52,4 @@ clean:
@$(RM_CMD_1) *.out $(RM_CMD_2)
@$(RM_CMD_1) *.yaml $(RM_CMD_2)

.PHONY: all test bindata clean
.PHONY: all test clean
246 changes: 0 additions & 246 deletions bindata/bindata.go

This file was deleted.

6 changes: 6 additions & 0 deletions fonts/fonts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fonts

import "embed"

//go:embed *
var FontFiles embed.FS
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ require (
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.4 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWp
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/g4s8/hexcolor v1.1.0 h1:PGG9472oBEMH4SMM//BMvZcS47ThkWR9YNJnMPDMDXo=
github.com/g4s8/hexcolor v1.1.0/go.mod h1:hG/pPv7k4KJmz8Zo/RQpawY6kwl7HraIBv12qOdrjo4=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-co-op/gocron v1.13.0 h1:BjkuNImPy5NuIPEifhWItFG7pYyr27cyjS6BN9w/D4c=
github.com/go-co-op/gocron v1.13.0/go.mod h1:GD5EIEly1YNW+LovFVx5dzbYVcIc8544K99D8UVRpGo=
github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
Expand Down
17 changes: 9 additions & 8 deletions util/transformations.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ import (
"io"
"io/ioutil"
"log"
"maintainman/fonts"
"os"
"path"
"regexp"
"strconv"
"strings"

"crypto/sha1"

"maintainman/bindata"

"github.com/g4s8/hexcolor"
"github.com/golang/freetype"
"github.com/golang/freetype/truetype"
Expand Down Expand Up @@ -139,7 +139,7 @@ func (t *TransformationInfo) ToTransformation() *Transformation {
}

fontBytes := []byte{}
var osErr, bindataErr error
var osErr, embedErr error

// Try to load font from os filesystem
if _, err := os.Stat(text.FontPath); os.IsNotExist(err) {
Expand All @@ -152,14 +152,15 @@ func (t *TransformationInfo) ToTransformation() *Transformation {
}
}

// Try to load font from bindata
// Try to load font from embed file
if osErr != nil {
fontBytes, bindataErr = bindata.Asset(text.FontPath)
_, file := path.Split(text.FontPath)
fontBytes, embedErr = fonts.FontFiles.ReadFile(file)
}

// if not found in both os filesystem and bindata
if osErr != nil && bindataErr != nil {
panic(fmt.Errorf("font does not exist in both os file and bindata (transformation %s): osErr: %+v; binDataErr: %+v", t.Name, osErr, bindataErr))
// if not found in both os filesystem and embed file
if osErr != nil && embedErr != nil {
panic(fmt.Errorf("font does not exist in both os file and embed file (transformation %s): osErr: %+v; binDataErr: %+v", t.Name, osErr, embedErr))
}

font, err := freetype.ParseFont(fontBytes)
Expand Down

0 comments on commit 8239e30

Please sign in to comment.