forked from wuhan005/Elaina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelaina.go
47 lines (38 loc) · 1000 Bytes
/
elaina.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
package main
import (
"os"
log "unknwon.dev/clog/v2"
"github.com/wuhan005/Elaina/internal/db"
"github.com/wuhan005/Elaina/internal/route"
)
func main() {
_ = log.NewConsole()
defer log.Stop()
// Check environment config, make sure the application is safe enough.
appURL := os.Getenv("APP_URL")
appPassword := os.Getenv("APP_PASSWORD")
appContainerPath := os.Getenv("APP_CONTAINER_PATH")
if appURL == "" {
log.Fatal("Empty APP_URL")
}
if appPassword == "" || len(appPassword) < 8 {
log.Fatal("APP_PASSWORD is not strong enough")
}
if appContainerPath == "" {
log.Fatal("APP_CONTAINER_PATH is empty")
}
err := os.MkdirAll("/elaina/volume", 0755)
if err != nil {
log.Fatal("Failed to create path /elaina/volume: %v", err)
}
log.Trace("Create /elaina/volume succeed!")
err = db.Init()
if err != nil {
log.Fatal("Failed to connect to database: %v", err)
}
r := route.New()
err = r.Run()
if err != nil {
log.Fatal("Failed to start HTTP server: %v", err)
}
}