-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
92 lines (80 loc) · 1.6 KB
/
main.go
File metadata and controls
92 lines (80 loc) · 1.6 KB
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
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"embed"
"errors"
"log"
"os"
"strconv"
_ "github.com/go-sql-driver/mysql"
_ "github.com/joho/godotenv/autoload"
"github.com/open-function-computers-llc/uptime/server"
)
//go:embed dist/*
var dist embed.FS
// version can be changed by build flags
var Version = "latest-dev"
func main() {
err := verifyVaildEnv()
if err != nil {
log.Fatal(err.Error())
os.Exit(1)
}
server, err := server.Create(dist, os.Getenv("APP_URL"))
if err != nil {
log.Fatal(err.Error())
os.Exit(1)
}
err = server.Serve()
if err != nil {
log.Fatal(err.Error())
os.Exit(1)
}
}
func verifyVaildEnv() error {
requiredKeys := []string{
"APP_PORT",
"APP_URL",
"APP_ENV",
"SMTP_HOST",
"SMTP_USER",
"SMTP_PASSWORD",
"SMTP_PORT",
"DB_TYPE",
"DB_USER",
"DB_PASSWORD",
"DB_NAME",
"DB_HOST",
"DB_PORT",
"INTERVAL_OK_RECHECK",
"INTERVAL_ERROR_RECHECK",
"INTERVAL_HOW_LONG_FOR_SITE_TIMEOUT",
"DANGER_SECONDS",
"EMERGENCY_SECONDS",
}
for _, key := range requiredKeys {
if os.Getenv(key) == "" {
return errors.New("missing env: " + key)
}
}
// supported DB engines
if os.Getenv("DB_TYPE") != "mysql" && os.Getenv("DB_TYPE") != "mariadb" {
return errors.New("supported db engines are mysql or mariadb")
}
requiredKeysThatAreInts := []string{
"APP_PORT",
"SMTP_PORT",
"DB_PORT",
"INTERVAL_OK_RECHECK",
"INTERVAL_ERROR_RECHECK",
"INTERVAL_HOW_LONG_FOR_SITE_TIMEOUT",
"DANGER_SECONDS",
"EMERGENCY_SECONDS",
}
for _, key := range requiredKeysThatAreInts {
_, err := strconv.Atoi(os.Getenv(key))
if err != nil {
return err
}
}
return nil
}