-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (71 loc) · 1.8 KB
/
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
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
package main
import (
"embed"
"fmt"
"os"
"github.com/sirupsen/logrus"
_ "github.com/volatiletech/authboss-renderer"
abrenderer "github.com/volatiletech/authboss-renderer"
_ "github.com/mstarongithub/mk-plugin-repo/auth-old"
authold "github.com/mstarongithub/mk-plugin-repo/auth-old"
"github.com/mstarongithub/mk-plugin-repo/config"
"github.com/mstarongithub/mk-plugin-repo/fswrapper"
"github.com/mstarongithub/mk-plugin-repo/server"
"github.com/mstarongithub/mk-plugin-repo/storage"
"github.com/mstarongithub/mk-plugin-repo/util"
)
const DB_DEFAULT_FILE = "db.sqlite"
//go:embed frontend/build frontend/build/_app/*
var frontendFS embed.FS
func main() {
setLogLevelFromEnv()
_, err := config.ReadConfig(nil)
if err != nil {
logrus.WithError(err).Warnln("Err reading config, using default")
config.SetGlobalToDefault()
}
err = util.CreateFileIfNotExists(DB_DEFAULT_FILE)
if err != nil {
panic(err)
}
store, err := storage.NewStorage(DB_DEFAULT_FILE, nil)
if err != nil {
panic(err)
}
ab, err := authold.SetupAuthboss(
&store,
[]byte("placeholder string"),
[]byte("placeholder string"),
abrenderer.NewEmail("/auth", "ab_views"),
)
if err != nil {
panic(err)
}
httpServer, err := server.NewServer(
fswrapper.NewFSWrapper(frontendFS, "frontend/build/", false),
ab,
&store,
)
if err != nil {
panic(err)
}
panic(httpServer.Run(":8080"))
}
func setLogLevelFromEnv() {
level := os.Getenv("MK_REPO_LOG_LEVEL")
fmt.Printf("Log level received from env: %s\n", level)
switch level {
case "debug":
logrus.SetLevel(logrus.DebugLevel)
case "info":
logrus.SetLevel(logrus.InfoLevel)
case "warn":
logrus.SetLevel(logrus.WarnLevel)
case "error":
logrus.SetLevel(logrus.ErrorLevel)
case "fatal":
logrus.SetLevel(logrus.FatalLevel)
default:
logrus.SetLevel(logrus.WarnLevel)
}
}