-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
39 lines (35 loc) · 915 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
package main
import (
"log"
"os"
"time"
"github.com/joho/godotenv"
"github.com/trsnaqe/protondb-api/pkg/server"
"github.com/trsnaqe/protondb-api/pkg/services/background_services"
"github.com/trsnaqe/protondb-api/pkg/storage"
)
var updateInterval = 24 * 30 * time.Hour // Change this to your desired update interval
func main() {
if os.Getenv("PORT") == "" {
// Load .env file if not running on Heroku
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")
}
}
err := storage.ConnectDB()
if err != nil {
panic(err)
}
background_services.SetUpdateInterval(updateInterval)
if updateInterval > 0 { // Don't start the goroutine if updateInterval is zero
go background_services.ProcessReportsBackground(updateInterval)
}
defer storage.CloseDB()
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
server := server.NewServer()
server.Run(":" + port)
}