-
Notifications
You must be signed in to change notification settings - Fork 0
/
hid.go
81 lines (70 loc) · 1.46 KB
/
hid.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package hid
import (
"bytes"
"embed"
"encoding/json"
"io/fs"
"text/template"
"time"
"github.com/juho05/log"
"github.com/juho05/h-id/config"
)
var StartTime = time.Now()
//go:embed data
var dataFS embed.FS
var (
HTMLFS fs.FS
StaticFS fs.FS
EmailFS fs.FS
SQLiteMigrationsFS fs.FS
PostgresMigrationsFS fs.FS
)
var OpenIDConfiguration []byte
//go:embed data/default_profile_picture.jpg
var DefaultProfilePicture []byte
func Initialize() {
var err error
HTMLFS, err = fs.Sub(dataFS, "data/html")
if err != nil {
log.Fatal(err)
}
StaticFS, err = fs.Sub(dataFS, "data/static")
if err != nil {
log.Fatal(err)
}
EmailFS, err = fs.Sub(dataFS, "data/email")
if err != nil {
log.Fatal(err)
}
SQLiteMigrationsFS, err = fs.Sub(dataFS, "data/sql/sqlite/migrations")
if err != nil {
log.Fatal(err)
}
PostgresMigrationsFS, err = fs.Sub(dataFS, "data/sql/postgres/migrations")
if err != nil {
log.Fatal(err)
}
openIDConfig, err := template.ParseFS(dataFS, "data/openid_configuration.tmpl.json")
if err != nil {
log.Fatal(err)
}
type tmplData struct {
BaseURL string
}
buffer := bytes.Buffer{}
err = openIDConfig.Execute(&buffer, tmplData{
BaseURL: config.BaseURL(),
})
if err != nil {
log.Fatal(err)
}
var oidConfig map[string]any
err = json.Unmarshal(buffer.Bytes(), &oidConfig)
if err != nil {
log.Fatal(err)
}
OpenIDConfiguration, err = json.Marshal(oidConfig)
if err != nil {
log.Fatal(err)
}
}