-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata_live.go
More file actions
64 lines (58 loc) · 1.51 KB
/
data_live.go
File metadata and controls
64 lines (58 loc) · 1.51 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
//go:build live
package gobookmarks
import (
"html/template"
"log"
"os"
"path/filepath"
)
func init() {
log.Printf("Live data mode")
}
func GetCompiledTemplates(funcs template.FuncMap) *template.Template {
t := template.New("").Funcs(funcs)
// When running `go test ./cmd/gobookmarks` the working dir is `./cmd/gobookmarks`
// so `./templates` might resolve to the CLI templates directory instead of the main one.
// We specifically look for mainPage.gohtml to ensure we found the web application templates.
fsPath := "./templates"
if _, err := os.Stat(filepath.Join(fsPath, "mainPage.gohtml")); os.IsNotExist(err) {
fsPath = "../../templates"
}
if _, err := os.Stat(filepath.Join(fsPath, "mainPage.gohtml")); os.IsNotExist(err) {
fsPath = "../templates"
}
fsys := os.DirFS(fsPath)
parsed, err := ParseFSRecursive(t, fsys, ".", ".gohtml")
if err != nil {
log.Printf("ParseFSRecursive error: %v", err)
}
return template.Must(parsed, err)
}
func GetMainCSSData() []byte {
fsPath := "main.css"
if _, err := os.Stat(fsPath); os.IsNotExist(err) {
fsPath = "../../main.css"
}
if _, err := os.Stat(fsPath); os.IsNotExist(err) {
fsPath = "../main.css"
}
b, err := os.ReadFile(fsPath)
if err != nil {
panic(err)
}
return b
}
func GetFavicon() []byte {
fsPath := "logo.png"
if _, err := os.Stat(fsPath); os.IsNotExist(err) {
fsPath = "../../logo.png"
}
if _, err := os.Stat(fsPath); os.IsNotExist(err) {
fsPath = "../logo.png"
}
b, err := os.ReadFile(fsPath)
if err != nil {
panic(err)
}
return b
}