zaj-e / Golang-Web-Service

Some steps and guidance to develop a REST-like API in Go. Includes options for HTTP servers, HTTP routers, Database ORMS/Migration libraries, as well as some popular web frameworks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Things we need to do

  • Support HTTP/2
  • Automatically install TLS certificates (echo)

Summary of tools that will help


Web Server

Requirements

HTTP server should have a default timeout value.

Examples

  • net/http lib has a http server implementation
  • fasthttp lib has a blazing fast http server
  • NGINX is a production ready web server

Migrations

Examples


HTTP ROUTERS

Context

httprouter is fast. gorilla mux is slower. But then again we are talking about routing, and unless all your microservice does is routing then it won't be the bottleneck. Database access or whatever other processing is likely to take longer. So it is also a matter of what extra features you need when choosing a plain router vs a framework vs the stdlib.

Examples

Some old benchmarls: https://github.com/julienschmidt/go-http-routing-benchmark#conclusions


Database Drivers

Examples


Database Libraries

Examples

SQLX

Features:

Usage:


ORM

Features

In contrast to a sql library, an ORM gives you a unified syntax, which it's loosely coupled from a particular database. It would be a pain if you are selling a product to enterprises and you had to support oracle and Sql server at the same time. Some ORM implementation select all row and and do filter internally. For example, if you do select on table A where Id = 1, a bad ORM implementation will select all row in table A (which cause large memory usage on your application) and then filter the result internally. That is just select operation. If you use a lot of join, it would get worse.

Examples

GORM

Pros: Saves you the verbosity of SQL + manually mapping fields, helps with managing migrations (https://www.reddit.com/r/golang/comments/a6yo8k/do_you_use_database_in_your_go_project/ebz0s5f?utm_source=share&utm_medium=web2x)

Cons: Complicated queries are better handled by sql directly. (https://www.reddit.com/r/golang/comments/fzs8p1/what_orm_are_you_use/fn65ugr?utm_source=share&utm_medium=web2x)

XORM

It's sort of an ehancement of stdlib and a superset of sqlx. It does:


Complete web Frameworks

  • Beego
  • Buffalo

Micro web Frameworks

Examples

Echo

Pros: Cons:

About

Some steps and guidance to develop a REST-like API in Go. Includes options for HTTP servers, HTTP routers, Database ORMS/Migration libraries, as well as some popular web frameworks.

License:Apache License 2.0


Languages

Language:Go 100.0%