REST Servers in Go: Part 1 – standard library

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

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

    Go net/http configurable handler to handle CORS requests (by rs)

  • Nice demo. A few things you could add to make this more realistic to something that gets shipped:

    -CORS support. Deploy this to a non-local domain and try to reach it from a web browser and it will fail. I like https://github.com/rs/cors. I had rolled my own but then moved to that library.

    - input validation. I like go-playground/validator.

    The other big issue is the locking by hand around the task store. In reality usually there would be a database to handle concurrent read/writes. I use SQLite in production. I know this is just a demo and you want to use just stdlib, but serializing all data access is sort of unacceptable as a solution in a concurrent language like Go. When I'm not handling concurrency with SQLite I like to implement The actor pattern, having a persistent goroutine listen and respond to "taskstore" requests via channels.

  • statik

    Embed files into a Go executable

  • > I've had this a few times, most recently with "how do I add this data file to my binary". At least that one made it to master now, and will be in 1.16!

    And before 1.16, there is statik: https://github.com/rakyll/statik.

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

    go.rice is a Go package that makes working with resources such as html,js,css,images,templates, etc very easy.

  • How does statik compare to rice, which is what I had assumed everyone was using: https://github.com/GeertJohan/go.rice

  • oapi-codegen

    Generate Go client and server boilerplate from OpenAPI 3 specifications

  • It depends on what the struct contains. I have developed many Go API's professionally at several companies since Go 1.1, and all my servers and up looking like a server struct with only a few fields - a database, AWS client object, and some prometheus metrics. The logic is typically split among many files, all implementing receivers on that struct.

    If you have independent, different elements in that API, you break them out into separate "servers" but still register the endpoints on the same HTTP handler.

    I know that people don't like external libraries too much, but I'd like to plug my own here. You declare your API in OpenAPI 3.0 (aka, Swagger) and it generates your server and models for you, so all you need to do is write the business logic. (https://github.com/deepmap/oapi-codegen)

  • goa

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

  • - similar to grpc gateway you just need to conform to the generated code’s service interface.

    I believe it supports, http, websocket and grpc.

    [1]https://github.com/goadesign/goa

  • 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