-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Yinebeb-01/mongo-repo
Mongo repo
- Loading branch information
Showing
30 changed files
with
467 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/glue/route" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/handler/middleware" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/handler/rest" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/repository/gorm" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/core/service" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
"github.com/gin-gonic/gin" | ||
dump "github.com/tpkeeper/gin-dump" | ||
) | ||
|
||
var ( | ||
videoRepository = gorm.NewVideoRepository() | ||
loginService = service.NewLoginService() | ||
jwtService = service.NewJWTService() | ||
|
||
videoService = service.New(videoRepository) | ||
videoHandler = rest.InitVideo(videoService) | ||
loginHandler = rest.InitLogin(loginService, jwtService) | ||
) | ||
|
||
func main() { | ||
configOutput() | ||
|
||
router := gin.New() | ||
// dump is an alise of gin-dum, used for debugging. | ||
router.Use(gin.Recovery(), middleware.Logger(), dump.Dump()) | ||
router.Static("/css", "./internal/adapter/templates/css") | ||
router.LoadHTMLGlob("./internal/adapter/templates/*.html") | ||
|
||
v1 := router.Group("/v1") | ||
route.InitVideoRoute(v1, videoHandler) | ||
route.InitLoginRoute(v1, loginHandler) | ||
|
||
log.Println("router initialized") | ||
|
||
port := os.Getenv("PORT") | ||
if port == "" { | ||
port = "8080" | ||
} | ||
router.Run(":" + port) | ||
} | ||
|
||
// configOutput create a custom logger file to see debugging outputs. | ||
func configOutput() { | ||
writer, err := os.Create("hexagonal_arch.log") | ||
if err != nil { | ||
log.Println("unable to create log file") | ||
} | ||
gin.DefaultWriter = io.MultiWriter(os.Stdout, writer) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package glue | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
type Router struct { | ||
Method string | ||
Path string | ||
Handler gin.HandlerFunc | ||
} | ||
|
||
func RegisterRoutes(group *gin.RouterGroup, routes []Router, middleware []gin.HandlerFunc) { | ||
for _, route := range routes { | ||
var handler []gin.HandlerFunc | ||
handler = append(handler, middleware...) | ||
handler = append(handler, route.Handler) | ||
group.Handle(route.Method, route.Path, handler...) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package route | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/glue" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/core/port" | ||
"net/http" | ||
) | ||
|
||
func InitLoginRoute(grp *gin.RouterGroup, handler port.LoginHandler) { | ||
loginRoutes := []glue.Router{ | ||
{ | ||
Method: http.MethodPost, | ||
Path: "/login", | ||
Handler: handler.Login, | ||
}, | ||
} | ||
|
||
// Login Endpoint: Authentication | ||
glue.RegisterRoutes(grp.Group(""), loginRoutes, []gin.HandlerFunc{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package route | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/glue" | ||
middlewares2 "gitlab.com/Yinebeb-01/hexagonalarch/internal/adapter/handler/middleware" | ||
"gitlab.com/Yinebeb-01/hexagonalarch/internal/core/port" | ||
"net/http" | ||
) | ||
|
||
func InitVideoRoute(grp *gin.RouterGroup, video port.VideoHandler) { | ||
videoRoutes := []glue.Router{ | ||
{ | ||
Method: http.MethodPost, | ||
Path: "/videos", | ||
Handler: video.Save, | ||
}, | ||
{ | ||
Method: http.MethodDelete, | ||
Path: "/videos/:id", | ||
Handler: video.Delete, | ||
}, | ||
{ | ||
Method: http.MethodPut, | ||
Path: "/videos/:id", | ||
Handler: video.Update, | ||
}, | ||
{ | ||
Method: http.MethodGet, | ||
Path: "/test", | ||
Handler: func(ctx *gin.Context) { | ||
ctx.JSON(http.StatusOK, gin.H{ | ||
"Message": "hello", | ||
}) | ||
}, | ||
}, | ||
} | ||
viewRoutes := []glue.Router{ | ||
{ | ||
Method: http.MethodGet, | ||
Handler: video.ShowAll, | ||
Path: "/videos", | ||
}, | ||
} | ||
|
||
//apiRoute group used to group 'api/*' endpoints. | ||
glue.RegisterRoutes(grp.Group("/api"), videoRoutes, []gin.HandlerFunc{middlewares2.AuthorizeJWT()}) | ||
//viewRoute Group will use to render static files | ||
glue.RegisterRoutes(grp.Group("/view"), viewRoutes, []gin.HandlerFunc{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
middlewares/logger.go → ...rnal/adapter/handler/middleware/logger.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package middlewares | ||
package middleware | ||
|
||
import ( | ||
"fmt" | ||
|
Oops, something went wrong.