-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (43 loc) · 1 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
package main
import (
"embed"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/Dev-Siri/gedis/core"
"github.com/Dev-Siri/gedis/db"
"github.com/Dev-Siri/gedis/embeds"
)
//go:embed pages
var PagesFS embed.FS
//go:embed public
var PublicFS embed.FS
func main() {
log.Println("Starting Gedis server")
port := os.Getenv("PORT")
if port == "" {
log.Printf("WARN: Port environment variable not found. Using 5000 instead.")
port = "5000"
}
embeds.Pages = PagesFS
embeds.StaticFiles = PublicFS
go core.StartServer(port)
log.Printf("Gedis server listening on port %s\n", port)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)
go func() {
<-interrupt
fmt.Println("\n(Info) Shutting down Gedis server")
os.Exit(0)
}()
if err := db.InitializeDB(); err != nil {
log.Fatalf("Database initialization failed")
return
}
// Runs every 5 seconds and checks the db
// for expired values & other stuff then deletes it
go db.CleanDB()
core.RunCLI()
}