Beginner-friendly API made with Go following hexagonal architecture.

This page summarizes the projects mentioned and recommended in the original post on /r/golang

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • Public-Library

    Clean Code & Hexagonal Architecture API in Go - a beginner-friendly example.

  • Public Library GitHub Repository

  • dockertest

    Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.

  • I've used dockertest a bunch and it is really amazing.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • go-envconfig

    A Go library for parsing struct tags from environment variables.

  • Also, I put config in the package that needs it using something like this instead of Viper: https://github.com/sethvargo/go-envconfig And then at the entry point make another config that includes all the structs from the packages and inject them after bulk reading in. The beauty of this is I can take a package for reuse and drop it into another project. It’s errors and config are right there with it. Also this reduces cognitive load of trying to find everything in big projects (or dig through a 1000 lines in a centralized location).

  • zap

    Blazing fast, structured, leveled logging in Go.

  • For logging: I recommend using Uber Zap https://github.com/uber-go/zap It will log stack backtraces and makes it super easy to debug errors when deployed. I typically log in the business logic and not below. And log at the entry for failures to start the system. Maybe not necessary for this example, but it’s an essential piece of any API backend.

  • goa

    🌟 Goa: Elevate Go API development! 🚀 Streamlined design, automatic code generation, and seamless HTTP/gRPC support. ✨

  • One of the biggest issues I see is that you are using the same models for API as you are for the database. That wouldn’t fly in a real work system. And even though your doing simple CRUD I would introduce another layer for business logic. You should never have the Controller calling you database code directly. It never “stays” that simplistic. One of the easiest ways to deal with this is to use Goa. https://goa.design/ It takes care of generating your API models and it creates the Interfaces to implement for your business logic. Furthermore it creates OpenAPI documentation (something missing in this design that is a must for commercial development).

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts