-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (37 loc) · 792 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
40
41
42
43
44
45
46
47
48
package main
import (
i "ShelterChatBackend/Api/internal"
"ShelterChatBackend/Api/database"
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
func main() {
database.SetupDatabase()
handler := i.NewRouter()
port := os.Getenv("API_PORT")
if port == "" {
port = "8808"
log.Printf("Port auf Default gesetzt: %s\n", port)
}
srv := &http.Server{
Addr: ":" + port,
Handler: handler,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
IdleTimeout: 120 * time.Second,
}
go func() {
log.Println("ShelterChat Api gestartet")
srv.ListenAndServe()
}()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
srv.Shutdown(ctx)
}