/myapp

🐣 How to build a Dockerized RESTful API application using Go.

Primary LanguageGoMIT LicenseMIT

Learning Cloud Native Go - myapp

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 commit messages and step- branches for a step by step guild. (Blog: Coming soon!)

Points to Highlight

πŸ’­ Hope to use Wire for Compile-time Dependency Injection in the future.

Endpoints

endpoints

Docker Image Sizes

REPOSITORY                 TAG                 SIZE
myapp_app                  latest              58.7MB
myapp_db                   latest              233MB

Design Decisions & Project Folder Structure

  • Store Docker related files inside the docker folder. But keep the docker-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
β”‚  └── mariadb
β”‚     └── Dockerfile
β”œβ”€β”€ docker-compose.yml
β”‚
β”œβ”€β”€ cmd
β”‚  β”œβ”€β”€ app
β”‚  β”‚  └── main.go
β”‚  └── migrate
β”‚     └── main.go
β”‚
β”œβ”€β”€ migrations
β”‚  └── 20190805170000_create_books_table.sql
β”‚
β”œβ”€β”€ app
β”‚  β”œβ”€β”€ app
β”‚  β”‚  β”œβ”€β”€ app.go
β”‚  β”‚  β”œβ”€β”€ bookHandler.go
β”‚  β”‚  β”œβ”€β”€ heathHandler.go
β”‚  β”‚  └── indexHandler.go
β”‚  β”œβ”€β”€ handler
β”‚  β”‚  β”œβ”€β”€ handler.go
β”‚  β”‚  └── logEntry.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 prefer app/server/server.go or http/app/app.go

Form Validation

Form validation

Logs

Logs in app init Logs in crud