🚚 Embed the resources

This commit is contained in:
Andreas Schneider 2021-03-06 14:21:30 +01:00
parent 247c750932
commit 79d322de14
1 changed files with 10 additions and 8 deletions

18
main.go
View File

@ -1,9 +1,9 @@
package main
import (
"embed"
"encoding/json"
"fmt"
"os"
"sync"
"fyne.io/fyne/v2"
@ -15,6 +15,9 @@ import (
"github.com/sahilm/fuzzy"
)
//go:embed data/gitmojis.json data/images
var data embed.FS
type Gitmoji struct {
Emoji string
Code string
@ -65,13 +68,13 @@ func main() {
currentId := 0
for i, gitmoji := range gitmojiData.Gitmojis {
res, err := fyne.LoadResourceFromPath("data/images/" + gitmoji.Name + ".png")
b, err := data.ReadFile("data/images/" + gitmoji.Name + ".png")
if err != nil {
panic(err)
}
allEntries[i] = &GitmojiEntry{
Gitmoji: gitmoji,
Icon: res,
Icon: fyne.NewStaticResource(gitmoji.Name, b),
}
allTerms[i] = gitmoji.Name + " " + gitmoji.Description
}
@ -195,15 +198,14 @@ func main() {
}
func loadData() (*GitmojiData, error) {
f, err := os.Open("data/gitmojis.json")
b, err := data.ReadFile("data/gitmojis.json")
if err != nil {
return nil, fmt.Errorf("cannot load gitmoji file: %w", err)
return nil, fmt.Errorf("cannot read gitmoji data: %w", err)
}
defer f.Close()
var result GitmojiData
if err := json.NewDecoder(f).Decode(&result); err != nil {
return nil, fmt.Errorf("cannot load gitmoji file: %w", err)
if err := json.Unmarshal(b, &result); err != nil {
return nil, fmt.Errorf("cannot decode gitmoji data: %w", err)
}
return &result, nil