File tree Expand file tree Collapse file tree 2 files changed +37
-27
lines changed
Expand file tree Collapse file tree 2 files changed +37
-27
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4- "fmt"
5-
6- "github.com/pauljamescleary/gomin/pkg/common/config"
7- "github.com/pauljamescleary/gomin/pkg/common/db"
8- "github.com/pauljamescleary/gomin/pkg/common/handler"
9-
10- "github.com/labstack/echo/v4"
11- "github.com/labstack/echo/v4/middleware"
4+ router "github.com/pauljamescleary/gomin/pkg/common"
125)
136
147func main () {
15- e := echo .New ()
16-
17- // Middleware
18- e .Use (middleware .Logger ())
19- e .Use (middleware .Recover ())
20-
21- cfg , _ := config .LoadConfig ()
22- fmt .Printf ("*** DB URL %s" , cfg .DbUrl )
23-
24- database := db .NewDatabase (cfg )
25- userRepo , _ := db .NewUserRepository (database )
26- handler := handler .NewHandler (userRepo )
27-
28- // Routes
29- // e.GET("/users", api.GetAllUsers)
30- e .POST ("/users" , handler .CreateUser )
31- // e.GET("/users/:id", api.GetUser)
32- // e.PUT("/users/:id", api.UpdateUser)
33- // e.DELETE("/users/:id", api.DeleteUser)
8+ e := router .SetupRouter ()
349
3510 // Start server
3611 e .Logger .Fatal (e .Start (":1323" ))
Original file line number Diff line number Diff line change 1+ package router
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/pauljamescleary/gomin/pkg/common/config"
7+ "github.com/pauljamescleary/gomin/pkg/common/db"
8+ "github.com/pauljamescleary/gomin/pkg/common/handler"
9+
10+ "github.com/labstack/echo/v4"
11+ "github.com/labstack/echo/v4/middleware"
12+ )
13+
14+ func SetupRouter () * echo.Echo {
15+ e := echo .New ()
16+
17+ // Middleware
18+ e .Use (middleware .Logger ())
19+ e .Use (middleware .Recover ())
20+
21+ cfg , _ := config .LoadConfig ()
22+ fmt .Printf ("*** DB URL %s" , cfg .DbUrl )
23+
24+ database := db .NewDatabase (cfg )
25+ userRepo , _ := db .NewUserRepository (database )
26+ handler := handler .NewHandler (userRepo )
27+
28+ // Routes
29+ // e.GET("/users", api.GetAllUsers)
30+ e .POST ("/users" , handler .CreateUser )
31+ // e.GET("/users/:id", api.GetUser)
32+ // e.PUT("/users/:id", api.UpdateUser)
33+ // e.DELETE("/users/:id", api.DeleteUser)
34+ return e
35+ }
You can’t perform that action at this time.
0 commit comments