Tuesday, April 28, 2020

A Go http framework less good than the standard library

tl;dr: don't use "Echo" Go web framework.

Bad smell: "guide" documentation only, no "reference"

If you go to the project homepage there are two links that look like big buttons in the middle of the page, "GitHub" and "Get Started". Going to the "Get Started" "Guide" documentation there are lots of examples about how to use APIs, but nothing that explicitly spells out what the function signature is. I want to know exactly what it is and what I can do with it. It shows some methods on an object being used, but there's no reference document for that object listing out all of the things I might do with it. I had to read the source to figure out what the objects were and how to use them.

Bad smell: requires closures instead of interfaces

The Go standard library net/http package defines a Handler interface that passes in two objects, a Request and a ResponseWriter. Someone clever once figured out that you could also just pass a function pointer to this and it could satisfy the interface. Echo doesn't define interfaces but only function signatures. Thus it requires that any state be held in closures instead of structs. The net/http way allows for closures or structs. Requiring closures might be fine for Haskell or Scala but is bad Go style. The project I was working with which had adopted Echo had some triply nested closures to set up the functions that Echo would call. It was hard to tell exactly what scope was being captured to run each closure. A struct implementing an interface explicitly and clearly declares what values it needs to run. Clear simple explicit code that is easy to read and understand is the go way.