-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (41 loc) · 1.07 KB
/
main.go
File metadata and controls
53 lines (41 loc) · 1.07 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
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/martiriera/discogs-spotify/internal/infrastructure/config"
"github.com/martiriera/discogs-spotify/internal/infrastructure/container"
)
const (
shutdownTimeout = 10 * time.Second
)
func main() {
cfg, err := config.LoadConfig()
if err != nil {
log.Fatalf("Failed to load configuration: %v", err)
}
c := container.NewContainer(cfg)
server := c.GetHTTPServer()
// Start server in a goroutine
go func() {
log.Printf("Starting server on port %s", cfg.Server.Port)
if err := server.ListenAndServe(); err != nil {
if err.Error() != "http: Server closed" {
log.Fatalf("Server failed: %v", err)
}
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutting down server...")
ctx, cancel := context.WithTimeout(context.Background(), shutdownTimeout)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
log.Printf("Server forced to shutdown: %v", err)
}
log.Println("Server exited properly")
}