23 August 2022

Top List of Libraries for CRUD

You start a new CRUD project but you don't know which library to choose, you will find here the top libraries.

Sidorenko Konstantin
Sidorenko Konstantin thecampagnards

This post was written on 23 August 2022, the libraries can change, be in maintenance mode etc.

When you choose a library in Go, pay attention to several points:

  • look if the library is in maintenance mode
  • look at the number of stars
  • look at the date of the last commit

With these points you will have more or less an opinion on the reliability of this library.

HTTP Server

Generator

go-swagger

Brings to the go community a complete suite of fully-featured, high-performance, API components to work with a Swagger API: server, client and data model.

  • Generates a server from a swagger specification
  • Generates a client from a swagger specification
  • Generates a CLI (command line tool) from a swagger specification (alpha stage)
  • Supports most features offered by jsonschema and swagger, including polymorphism
  • Generates a swagger specification from annotated go code
  • Additional tools to work with a swagger spec
  • Great customization features, with vendor extensions and customizable templates

The go-swagger focus with code generation is to produce idiomatic, fast go code, which plays nice with golint, go vet etc.

It will also do the parameter checks for you, such as enums, minimum for numbers etc.

oapi-codegen

Is a code generator for OpenAPI 3.0, it can generate server, client, models etc. For the server generator it can generate code for echo, chi, Gin and net/http.

Manual Coding

fiber

Is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind.

echo

Simplifies the creation of web applications and restful APIs. If you have Python experience, you may find the framework similar to Flask.

With the rise of fiber which does almost the same thing with better performance, echo has a slight drop in popularity. But it’s still a classic in Go.

gin

Is a web framework written in Go. It features a martini-like API with performance that is up to 40 times faster thanks to httprouter.

With the rise of fiber which does almost the same thing with better performance, gin has a slight drop in popularity. But it’s still a classic in Go.

Database

Postgres

Generator

sql-to-go

Generates Go structures and functions based on an SQL files containing create tables and alter.

Manual Coding

bun

Is a lightweight Go ORM for PostgreSQL, MySQL, MSSQL, and SQLite. Bun is a rewrite of go-pg.

go-pg is still maintained and there is no urgency in rewriting go-pg apps in Bun, but new projects should prefer Bun over go-pg. And once you are familiar with the updated API, you should be able to migrate a 80-100k lines go-pg app to Bun within a single day.

It is usually easier to write complex queries with Bun rather than GORM. Out of the box, Bun has better integration with database-specific functionality, for example, PostgreSQL arrays. Bun is also faster, partly because Bun is smaller in size and scope.

Bun does not support such popular GORM features like automatic migrations, optimizer/index/comment hints, and database resolver.

Mongo

mongo-go-driver

Is the official MongoDB supported driver for Go.

Logger

zerolog

The zerolog package provides a fast and simple logger dedicated to JSON output.

Zerolog’s API is designed to provide both a great developer experience and stunning performance. Its unique chaining API allows zerolog to write JSON (or CBOR) log events by avoiding allocations and reflection.

Uber’s zap library pioneered this approach. Zerolog is taking this concept to the next level with a simpler to use API and even better performance.

zap

Blazing fast, structured, leveled logging in Go.

Config

cleanenv

Is a minimalistic configuration reader.

This is a simple configuration reading tool. It just does the following:

  • reads and parses configuration structure from the file
  • reads and overwrites configuration structure from environment variables
  • writes a detailed variable list to help output

viper

Viper is a complete configuration solution for Go applications including 12-Factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats. It supports:

  • setting defaults
  • reading from JSON, TOML, YAML, HCL, envfile and Java properties config files
  • live watching and re-reading of config files (optional)
  • reading from environment variables
  • reading from remote config systems (etcd or Consul), and watching changes
  • reading from command line flags
  • reading from buffer
  • setting explicit values

Viper can be thought of as a registry for all of your applications configuration needs.

References

List of awesome go tools: https://github.com/avelino/awesome-go

Categories

Golang Development