1
0
Fork 0
mirror of https://github.com/Luzifer/badge-gen.git synced 2024-11-08 13:20:02 +00:00

Replace bindata with go:embed

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-09-07 18:12:11 +02:00
parent 3f6103d473
commit 73b722d998
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
5 changed files with 10 additions and 287 deletions

4
app.go
View file

@ -221,7 +221,7 @@ func createBadge(title, text, color string) ([]byte, string) {
width := titleW + textW + 4*xSpacing
t, _ := Asset("assets/badgeTemplate.tpl")
t, _ := assets.ReadFile("assets/badgeTemplate.tpl")
tpl, _ := template.New("svg").Parse(string(t))
if c, ok := colorList[color]; ok {
@ -246,7 +246,7 @@ func generateETag(in []byte) string {
}
func handleDemoPage(res http.ResponseWriter, r *http.Request) {
t, _ := Asset("assets/demoPage.tpl.html")
t, _ := assets.ReadFile("assets/demoPage.tpl.html")
tpl, _ := template.New("demoPage").Parse(string(t))
examples := serviceHandlerDocumentationList{}

6
assets.go Normal file
View file

@ -0,0 +1,6 @@
package main
import "embed"
//go:embed assets/*
var assets embed.FS

File diff suppressed because one or more lines are too long

View file

@ -15,7 +15,7 @@ const (
)
func calculateTextWidth(text string) (int, error) {
binFont, _ := Asset("assets/DejaVuSans.ttf")
binFont, _ := assets.ReadFile("assets/DejaVuSans.ttf")
font, err := truetype.Parse(binFont)
if err != nil {
return 0, err

View file

@ -8,7 +8,7 @@ import (
func TestEmbeddedFontHash(t *testing.T) {
// Check the embedded font did not change
font, err := Asset("assets/DejaVuSans.ttf")
font, err := assets.ReadFile("assets/DejaVuSans.ttf")
if err != nil {
t.Errorf("Could not load embedded font: %s", err)
}