π± Cloud Native Application Development is one way of speeding up the building of web applications using microservices, containers, and orchestration tools.
This repository shows how to build a Dockerized RESTful API application in Go for a simple bookshelf.
- The idiomatic structure based on the resource-oriented design.
- The usage of Docker, Docker compose, Alpine images, and linters on development.
- Healthcheck and CRUD API implementations with OpenAPI specifications.
- The usage of Goose for the database migrations and GORM as the database ORM.
- The usage of Zerolog as the centralized Syslog logger.
- The usage of Validator.v10 as the form validator.
- The usage of GitHub actions to run tests and linters, generate OpenAPI specifications, and build and push production images to the Docker registry.
Name | HTTP Method | Route |
---|---|---|
Health | GET | /livez |
List Books | GET | /v1/books |
Create Book | POST | /v1/books |
Read Book | GET | /v1/books/{id} |
Update Book | PUT | /v1/books/{id} |
Delete Book | DELETE | /v1/books/{id} |
π‘ swaggo/swag : swag init -g cmd/api/main.go -o .swagger -ot yaml
Column Name | Datatype | Not Null | Primary Key |
---|---|---|---|
id | UUID | β | β |
title | TEXT | β | |
author | TEXT | β | |
published_date | DATE | β | |
image_url | TEXT | ||
description | TEXT | ||
created_at | TIMESTAMP | β | |
updated_at | TIMESTAMP | β | |
deleted_at | TIMESTAMP |
- DB: 241MB
- API
- Development environment: 655MB
- Production environment: 28MB ; π‘
docker build -f prod.Dockerfile . -t myapp_app
myapp
βββ cmd
β βββ api
β β βββ main.go
β βββ migrate
β βββ main.go
β
βββ api
β βββ resource
β β βββ book
β β β βββ handler.go
β β β βββ model.go
β β β βββ repository.go
β β β βββ repository_test.go
β β βββ common
β β β βββ err
β β β βββ err.go
β β βββ health
β β βββ handler.go
β β
β βββ router
β βββ middleware
β β βββ request_id.go
β β βββ request_id_test.go
β β βββ requestlog
β β β βββ handler.go
β β β βββ log_entry.go
β β βββ content_type.go
β β βββ content_type_test.go
β βββ router.go
β
βββ migrations
β βββ 00001_create_books_table.sql
β
βββ config
β βββ config.go
β
βββ util
β βββ logger
β β βββ logger.go
β βββ validator
β βββ validator.go
β
βββ .env
β
βββ go.mod
βββ go.sum
β
βββ docker-compose.yml
βββ Dockerfile
β
βββ prod.Dockerfile
βββ k8s
βββ app-configmap.yaml
βββ app-secret.yaml
βββ app-deployment.yaml
βββ app-service.yaml