Skip to content

πŸ–₯️ How to build a Dockerized RESTful API application using Go.

License

Notifications You must be signed in to change notification settings

erismaster/myapp

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

About

πŸ–₯️ How to build a Dockerized RESTful API application using Go.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 94.2%
  • Dockerfile 2.8%
  • TSQL 1.8%
  • Shell 1.2%