π± 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.
Name | HTTP Method | Route |
---|---|---|
Health | GET | /livez |
List Books | GET | /api/v1/books |
Create Book | POST | /api/v1/books |
Read Book | GET | /api/v1/books/{id} |
Update Book | PUT | /api/v1/books/{id} |
Delete Book | DELETE | /api/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
β βββ router
β β βββ router.go
β β
β βββ resource
β βββ health
β β βββ handler.go
β βββ book
β β βββ api.go
β β βββ handler.go
β β βββ model.go
β β βββ repository.go
β βββ common
β βββ err
β βββ err.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