-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (49 loc) · 1.57 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"net/http"
"os"
"github.com/go-playground/validator/v10"
"github.com/rs/zerolog/log"
"github.com/taepunphu/go-rest-api-structure/configs"
"github.com/taepunphu/go-rest-api-structure/controllers"
"github.com/taepunphu/go-rest-api-structure/database"
"github.com/taepunphu/go-rest-api-structure/repositories"
"github.com/taepunphu/go-rest-api-structure/routes"
"github.com/taepunphu/go-rest-api-structure/services"
"github.com/taepunphu/go-rest-api-structure/utils"
)
func main() {
log.Info().Msg("Starting Server at http://localhost:4000")
configPath := utils.GetConfigPath(os.Getenv("config"))
cfgFile, err := configs.LoadConfig(configPath)
if err != nil {
log.Err(err).Msgf("LoadConfig: %v", err)
}
cfg, err := configs.ParseConfig(cfgFile)
if err != nil {
log.Err(err).Msgf("ParseConfig: %v", err)
}
// Database
psqlDB, err := database.NewPsqlDB(cfg)
if err != nil {
log.Err(err).Msgf("Postgresql init: %s", err)
} else {
log.Err(err).Msgf("Postgres connected, Status: %#v", psqlDB)
}
validate := validator.New()
// Repository
productRepository := repositories.NewProductRepository(psqlDB)
// Service
productService := services.NewProductservice(productRepository, validate)
// Controller
productController := controllers.NewProductController(productService)
// Router
routes := routes.NewProductRoute(productController)
server := &http.Server{
Addr: cfg.Server.Port,
Handler: routes,
}
if errListen := server.ListenAndServe(); errListen != nil {
log.Err(errListen).Msgf("Error Listen And Serve: %v", errListen)
}
}