DEV Community


Discussion on: Blog with Go, Gin, MySQL and Docker - Part 2

jacobbishopxy profile image
Jacob Xie

Thanks for the great sharing! BTW, one thing I've noticed is that all the structs under api folder are using non-pointer fields. For example, why wouldn't we write PostRoute like this:

type PostRoute struct {
    Controller *controller.PostController
    Handler    *infrastructure.GinRouter
Enter fullscreen mode Exit fullscreen mode

And as a result, we can do main.go like below (using references):

func main() {
    router := infrastructure.NewGinRouter()
    db := infrastructure.NewDatabase()
    postRepository := repository.NewPostRepository(&db)
    postService := service.NewPostService(&postRepository)
    postController := controller.NewPostController(&postService)
    postRoute := routes.NewPostRoute(&postController, &router)



Enter fullscreen mode Exit fullscreen mode

Again, thanks for sharing!