-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathmain.go
44 lines (40 loc) · 1.08 KB
/
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
package main
import (
"fmt"
"github.com/gbrayhan/microservices-go/src/infrastructure/repository"
"github.com/gbrayhan/microservices-go/src/infrastructure/rest/middlewares"
"github.com/gbrayhan/microservices-go/src/infrastructure/rest/routes"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"net/http"
"os"
"strings"
"time"
)
func main() {
router := gin.Default()
router.Use(cors.Default())
DB, err := repository.InitDB()
if err != nil {
panic(fmt.Errorf("error inicializando la base de datos: %w", err))
}
router.Use(middlewares.ErrorHandler())
router.Use(middlewares.GinBodyLogMiddleware)
router.Use(middlewares.CommonHeaders)
routes.ApplicationRouter(router, DB)
port := os.Getenv("SERVER_PORT")
if port == "" {
port = "8080"
}
s := &http.Server{
Addr: ":" + port,
Handler: router,
ReadTimeout: 18000 * time.Second,
WriteTimeout: 18000 * time.Second,
MaxHeaderBytes: 1 << 20,
}
fmt.Printf("Servidor corriendo en http://localhost:%s\n", port)
if err := s.ListenAndServe(); err != nil {
panic(strings.ToLower(err.Error()))
}
}