Cloud Native Application Development is a one way of speeding up building web applications, using micro-services, containers and orchestration tools.
As the first step, this repository shows How to build a Dockerized RESTful API application using Go.
π‘ Refer learning-cloud-native-go.github.io or commit messages and
step-
branches for a step by step guild.
- Usage of Docker and Docker Compose.
- Usage of Golang and MySQL Alpine images.
- Usage of Docker Multistage builds.
- Liveness and Readiness APIs for K8s.
- Usage of Goose for Migrations.
- Usage of GORM as the ORM.
- Usage of Chi as the Router.
- Usage of Zerolog as the Logger.
- Usage of Validator.v10 as the Form Validator.
π Hope to use Wire for Compile-time Dependency Injection in the future.
- DB: 229MB
- App
- Development environment: 728MB
- Production environment: 21.8MB
π‘ Building Docker image for production
docker build -f docker/app/prod.Dockerfile . -t myapp_app
- Store Docker related files inside the
docker
folder. But keep thedocker-compose.yml
file in the project root. - Store executable packages inside the
cmd
folder. - Store database migrations inside the
migrations
folder. - Store main application code inside the
app
folder. - Store reusable packages like configs, utils, models and repositories in separate folders. This will be helpful if you are adding more executable applications to support web front-ends, publish/subscribe systems, document stores and etc.
.
βββ docker
β βββ app
β βββ bin
β β βββ init.sh
β β βββ wait-for-mysql.sh
β βββ Dockerfile
βββ docker-compose.yml
β
βββ cmd
β βββ app
β β βββ main.go
β βββ migrate
β βββ main.go
β
βββ migrations
β βββ 20190805170000_create_books_table.sql
β
βββ app
β βββ app
β β βββ app.go
β β βββ book_handler.go
β β βββ health_handler.go
β β βββ index_handler.go
β βββ requestlog
β β βββ handler.go
β β βββ log_entry.go
β βββ router
β βββ middleware
β β βββ content_type_json.go
β β βββ content_type_json_test.go
β βββ router.go
β
βββ config
β βββ config.go
β
βββ adapter
β βββ db
β β βββ db.go
β βββ gorm
β βββ gorm.go
β
βββ util
β βββ logger
β β βββ logger.go
β β βββ logger_test.go
β βββ validator
β βββ validator.go
β βββ validator_test.go
β
βββ model
β βββ book.go
βββ repository
β βββ book.go
β
βββ go.mod
βββ go.sum
π‘ About
app/app/app.go
; Some preferapp/server/server.go
orhttp/app/app.go