-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (35 loc) · 965 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
package main
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/pocockn/recs-api/config"
"github.com/pocockn/recs-api/persistance"
"github.com/pocockn/recs-api/recs/delivery"
"github.com/pocockn/recs-api/recs/store"
"log"
"net/http"
)
func main() {
config := config.NewConfig()
db, err := persistance.NewConnection(config)
if err != nil {
log.Fatal(err)
}
connection, err := db.Connect()
if err != nil {
log.Fatal(err)
}
e := echo.New()
//TODO: this should come from config.
e.Use(
middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"http://localhost:8081", "http://localhost:3000"},
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
}),
middleware.Logger(),
)
recRepo := store.NewRecsStore(connection)
echoHandler := delivery.NewHandler(config, recRepo)
echoHandler.Register(e)
e.Logger.Fatal(e.Start(":1323"))
}