-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
34 lines (31 loc) · 753 Bytes
/
Copy pathmain.go
File metadata and controls
34 lines (31 loc) · 753 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
package main
import (
"api-server/initialization"
"context"
"os"
"time"
)
func main() {
logger, router, mongoDbClient, err := initialization.Start()
if err != nil {
if logger != nil {
logger.Errorw("Cannot start application", "error", err)
}
os.Exit(1)
}
defer logger.Sync()
defer func() {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err = mongoDbClient.Disconnect(ctx); err != nil {
logger.Warnw("Cannot disconnect MongoDB cleanly", "error", err)
}
}()
// Start server
port := os.Getenv("HTTP_PORT")
logger.Infof("GIN - up and running with port: %s", port)
if err = router.Run(":" + port); err != nil {
logger.Error("Cannot start HTTP server", err)
os.Exit(1)
}
}