-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (42 loc) · 858 Bytes
/
main.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
package main
import (
"embed"
"flag"
"fmt"
"net/http"
)
//go:embed pages/*
var pages embed.FS
//go:embed cdn/*
var cdn embed.FS
var exit = make(chan error, 1)
var noshell bool
func main() {
flag.BoolVar(&noshell, "no-shell", false, "disables the cli")
flag.Parse()
defer db.Close()
http.HandleFunc("/", root)
http.HandleFunc("/register", register)
http.HandleFunc("/home", home)
http.HandleFunc("/settings", settings)
http.HandleFunc("/login", login)
http.HandleFunc("/api/v1/{endpoint...}", apiv1)
http.Handle("/cdn/", http.FileServer(http.FS(cdn)))
if !noshell {
go func() {
exit <- cli()
}()
}
go func() {
if err := http.ListenAndServe(port, nil); err != nil {
logError(err)
fmt.Println(err)
exit <- err
}
}()
logInfo(fmt.Errorf("server started"))
err := <-exit
if err != nil {
fmt.Println(err)
}
}