-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
embed.go
51 lines (42 loc) · 909 Bytes
/
embed.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ui
import (
"embed"
"io/fs"
"net/http"
"strings"
"github.com/go-spatial/tegola/internal/log"
)
//Embed UI dist Folder recursively
//go:embed dist/*
var dist embed.FS
const (
distDir = "dist"
assetsDir = "assets"
indexJSPrefix = "index-"
)
func GetDistFileSystem() http.FileSystem {
distFS := GetDistFS()
return http.FS(distFS)
}
func GetDistFS() fs.FS {
distFS, err := fs.Sub(dist, distDir)
if err != nil {
log.Fatal(err)
}
return distFS
}
func Version() string {
// read the assets/ directory so we can attempt to find the built .js file
files, err := fs.ReadDir(GetDistFS(), assetsDir)
if err != nil {
return ""
}
for _, entry := range files {
name := entry.Name()
if strings.HasPrefix(name, indexJSPrefix) && strings.HasSuffix(name, ".js") {
// expect it to be index-{version}.js
return name[len(indexJSPrefix) : len(name)-3]
}
}
return ""
}