/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 learning-cloud-native-go.github.io or commit messages and step- branches for a step by step guild.

Points to Highlight

💭 Hope to use Wire for Compile-time Dependency Injection in the future.

Endpoints

endpoints

Docker Image Sizes

  • 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

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
├── 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 prefer app/server/server.go or http/app/app.go

Form Validation

Form validation

Logs

Logs in app init Logs in crud