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.
- Usage of Docker and Docker Compose.
- Usage of Golang and MySQL Alpine images.
- Usage of Docker Multistage builds.
- Health API for K8s liveness & readiness.
- 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.
- DB: 230MB
- App
- Development environment: 667MB
- Production environment: 21MB
π‘ Building Docker image for production
docker build -f prod.Dockerfile . -t myapp_app
- 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 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-compose.yml
βββ Dockerfile
βββ prod.Dockerfile
β
βββ cmd
β βββ api
β β βββ main.go
β βββ migrate
β βββ main.go
β
βββ migrations
β βββ 00001_create_books_table.sql
β
βββ api
β βββ resource
β β βββ book
β β β βββ api.go
β β β βββ handler.go
β β β βββ model.go
β β β βββ repository.go
β β βββ common
β β β βββ err
β β β βββ err.go
β β βββ health
β β βββ handler.go
β β
β βββ router
β β βββ router.go
β β βββ middleware
β β βββ content_type_json.go
β β βββ content_type_json_test.go
β β
β βββ requestlog
β βββ handler.go
β βββ log_entry.go
β
βββ config
β βββ config.go
β
βββ util
β βββ logger
β β βββ logger.go
β β βββ logger_test.go
β βββ validator
β βββ validator.go
β βββ validator_test.go
β
βββ k8s
β βββ app-configmap.yaml
β βββ app-secret.yaml
β βββ app-deployment.yaml
β βββ app-service.yaml
β
βββ go.mod
βββ go.sum