Golang Gin CRUD RESTful with Go Modules, Wire, Gorm and MySQL built with Hexagonal Architecture and DDD
- Go Modules is a dependency management system introduced since Go 1.1+ https://blog.golang.org/using-go-modules
- Wire is a code generation tool providing compile-time dependency injection for Go https://github.com/google/wire
- Gin is a popular web framework written in Go https://github.com/gin-gonic/gin
- Gorm is an ORM library https://gorm.io/
├── cmd # Main applications for this project
│ └── server # Directory name matching executable
├── internal # Private application and library code
│ ├── api
│ ├── dao
│ ├── di # Dependency injection
│ └── service
└── pkg # Library code that's ok to use by external applications
├── adding # Adding context
├── authenticating # Authenticating context
├── deleting # Deleting context
├── listing # Listing context
└── storage # Persistance storage implementation
└── gorm # ORM Gorm
Generate wire_gen.go
for dependency injection
$ cd internal/di
$ wire
Build the project
$ cd cmd/server
$ go build main.go
Run the built (mysql instance dependency)
$ PORT=8000 DB_URL="root:@tcp(127.0.0.1:3360)/platform?charset=utf8&parseTime=True&loc=Local" ./cmd/server/server
- Add Template build environment. Check => https://github.com/thockin/go-build-template