myapp icon indicating copy to clipboard operation
myapp copied to clipboard

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

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.

Points to Highlight

Endpoints

endpoints

Docker Image Sizes

  • DB: 230MB
  • App
    • Development environment: 667MB
    • Production environment: 21MB

💡 Building Docker image for production docker build -f docker/app/prod.Dockerfile . -t myapp_app

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 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
├── docker
│  └── app
│     ├── bin
│     │  └── init.sh
│     ├── Dockerfile
│     └── prod.Dockerfile
│
├── cmd
│  ├── app
│  │  └── main.go
│  └── migrate
│     └── main.go
│
├── migrations
│  └── 20190805170000_create_books_table.sql
│
├── app
│  ├── service
│  │  ├── health
│  │  │  └── handler.go
│  │  ├── book
│  │  │  ├── app.go
│  │  │  ├── handler.go
│  │  │  ├── model.go
│  │  │  └── repository.go
│  │  └── error
│  │     └── handler.go
│  │
│  ├── router
│  │  ├── router.go
│  │  └── middleware
│  │     ├── content_type_json.go
│  │     └── content_type_json_test.go
│  │
│  └── requestlog
│     ├── handler.go
│     └── log_entry.go
│
├── config
│  └── config.go
│
├── adapter
│  ├── db
│  │  └── db.go
│  └── gorm
│     └── gorm.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

Form Validation

Form validation

Logs

Logs in app init Logs in crud