-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
43 lines (36 loc) · 730 Bytes
/
init.go
File metadata and controls
43 lines (36 loc) · 730 Bytes
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
package main
import (
"embed"
"fmt"
"io/fs"
"net/http"
"os"
)
//go:embed templates/index.html
var TemplateFiles embed.FS
//go:embed static
var StaticFiles embed.FS
var StaticFS http.FileSystem
var (
SharedDir string
)
func init() {
// find and prepare shared dir
if !PrepareSharedDir() {
err := os.MkdirAll(SharedDir, 0700)
if err != nil {
panic("failed to create shared dir")
}
}
// generate qr code
err := QREncode(fmt.Sprintf("http://%s:%s/", Config.IP, Config.Port))
if err != nil {
panic("failed to create qr code")
}
// strip prefix from static fs
sub, err := fs.Sub(StaticFiles, "static")
if err != nil {
panic("failed to strip 'static' from static files")
}
StaticFS = http.FS(sub)
}