Skip to content

πŸš€ How to build a Dockerized RESTful API application using Go.

License

Notifications You must be signed in to change notification settings

vsel/myapp

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

58 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Learning Cloud Native Go - myapp

🌱 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.

πŸ”‹ Batteries included

  • 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.

πŸš€ Endpoints

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

πŸ—„οΈ Database design

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

πŸ“¦ Container image sizes

  • DB: 241MB
  • API
    • Development environment: 655MB
    • Production environment: 28MB ; πŸ’‘docker build -f prod.Dockerfile . -t myapp_app

πŸ“ Project structure

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

πŸ“Έ Form validations and logs

Form validation

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 97.0%
  • Dockerfile 2.4%
  • Shell 0.6%