-
Notifications
You must be signed in to change notification settings - Fork 3
/
templates.go
60 lines (51 loc) · 1023 Bytes
/
templates.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
52
53
54
55
56
57
58
59
60
package page
import (
"embed"
"html/template"
"io/fs"
"os"
"github.com/macrat/lauth/config"
)
//go:embed html/*.tmpl
var templates embed.FS
func Load(conf config.TemplateConfig) (*template.Template, error) {
fsys, err := fs.Sub(templates, "html")
if err != nil {
return nil, err
}
t, err := template.ParseFS(fsys, "*.tmpl")
if err != nil {
return nil, err
}
if conf.LoginPage != "" {
raw, err := os.ReadFile(conf.LoginPage)
if err != nil {
return nil, err
}
_, err = t.Lookup("login.tmpl").Parse(string(raw))
if err != nil {
return nil, err
}
}
if conf.LogoutPage != "" {
raw, err := os.ReadFile(conf.LogoutPage)
if err != nil {
return nil, err
}
_, err = t.Lookup("logout.tmpl").Parse(string(raw))
if err != nil {
return nil, err
}
}
if conf.ErrorPage != "" {
raw, err := os.ReadFile(conf.ErrorPage)
if err != nil {
return nil, err
}
_, err = t.Lookup("error.tmpl").Parse(string(raw))
if err != nil {
return nil, err
}
}
return t, nil
}