i would really love to read a short super opinionated guide to Go web development by someone with the same values/requirements as me, like:
-
i would really love to read a short super opinionated guide to Go web development by someone with the same values/requirements as me, like:
- no magic (for example I think no ORM)
- stay pretty close to the standard library
- minimal dependencies
- very small sites, just a few pages/endpointscan't tell if this exists though, there are a lot of golang web dev guides out there but just from reading the TOC I can usually tell that I have different values from the authors
-
this golang post is brought to you by reading one million comments talking about gorm to finally discover that sqlx exists
(2/?)
-
@b0rk I wrote a web app recently by basically copying the layout of ted unangst's Honk https://humungus.tedunangst.com/r/honk
mux is the only dependency that he uses that I think is unnecessary with recent improvements to the stdlib, I prefer chi
-
@b0rk i have mixed feelings about sqlx
it does work as advertised, but i tripped up over a really stupid problem: it only takes the first expression in the file, and silently ignores the rest, which was a bad thing
the other problem was that i couldn't have two join based queries that returned the same data structure, so i ended up duplicating a lot of the logic
i used gorm afterwards, and the only footgun i hit was passing a value to .Scan(any) and not a ref. it was a much smoother ride
-
@b0rk why are ORMs considered "magic"?
-
@polotek hm I think what i mean is that I don't have much capacity for learning how libraries work
like I'd much rather have a bunch of extra boilerplate in my own code (that I can read) than rely on some core behaviour of a library that I'm probably going to forget how it works
-
-
@b0rk yeah that's understandable. I think I make a specific exception for ORMs when they're used responsibly. Because I think that figuring out a DB schema and a bunch of custom code to access it is often a higher burden when returning to an old project.
-
-
@polotek hm yeah I'm open to being sold on ORMs
-
-
@b0rk I think it takes time to build the right muscles around ORMs. They can very easily be footguns and feel like they're not worth it. Not to mention that many of the more recent ones are way overblown IMO. I think avoiding them is fine. I just wanted to get a little more understanding of where you're coming from.
-
@b0rk I don't have a guide, but I built a bunch of pieces that can be used for this.
I built my own stuff for static asset build (compatible with go:embed), JS bundling (same), signal handling, systemd socket activation, state machine building, etc.
Regarding SQL specifically, I always try to avoid it (in favour of in process storage libraries) or at most use it as a KV document store with json encoded data. YMMV of course.
I occasionally iterate through the new kids on the block which solve some other issue (logging, HTTP routers, etc)
-
@b0rk sorry for being lazy and self promoting, but all I can link to is this Makefile, which I think should provide you with a good a starting point to check if it matches what you're after: https://github.com/mariusor/oni/blob/master/Makefile#L43
-
-
@makeworld @b0rk pretty happy with https://git.sr.ht/~aw/fishbb as a base, there's some messy/awkward parts, but it's more or less a style I'm happy with