-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (30 loc) · 1.23 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
package main
import (
"fmt"
"golang-crud/config"
"golang-crud/controller"
"golang-crud/helper"
"golang-crud/repository"
"golang-crud/router"
"golang-crud/service"
"net/http"
"github.com/gorilla/handlers"
)
func main(){
fmt.Printf("Start server")
db := config.DatabaseConnection()
vehicleRepository := repository.NewVehicleRepository(db)
vehicleService := service.NewVehicleServiceImpl(vehicleRepository)
vehicleController := controller.NewVehicleController(vehicleService)
leadRepository := repository.NewLeadRepository(db)
leadService := service.NewLeadServiceImpl(leadRepository, vehicleRepository)
leadController := controller.NewLeadController(leadService, vehicleRepository)
routes := router.NewRouter(vehicleController, leadController)
allowedOrigins := handlers.AllowedOrigins([]string{"http://localhost:3000"})
allowedMethods := handlers.AllowedMethods([]string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"})
allowedHeaders := handlers.AllowedHeaders([]string{"Content-Type", "Authorization"})
corsRouter := handlers.CORS(allowedOrigins, allowedMethods, allowedHeaders)(routes)
server := http.Server{Addr: "localhost:5000", Handler: corsRouter}
err := server.ListenAndServe()
helper.PanicIfError(err)
}