-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
48 lines (39 loc) · 943 Bytes
/
Copy pathmain.go
File metadata and controls
48 lines (39 loc) · 943 Bytes
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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/joho/godotenv"
"github.com/vit0-9/utils_api/pkg/utils"
)
func main() {
err := godotenv.Load()
if err != nil {
log.Println("WARN: Error loading .env file, using environment variables from system if set.")
}
cityDBPath := os.Getenv("MMDB_CITY_PATH")
asnDBPath := os.Getenv("MMDB_ASN_PATH")
utils.LoadMaxMindDBs(cityDBPath, asnDBPath)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-quit
log.Println("Shutting down server...")
utils.CloseMaxMindDBs() // Close both databases
os.Exit(0)
}()
app, err := NewApp()
if err != nil {
log.Fatalf("Failed to initialize application: %v", err)
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
addr := ":" + port
if err := app.Start(addr); err != nil {
log.Fatalf("Failed to start server: %v", err)
utils.CloseMaxMindDBs()
}
}