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