Stacks that lurk in the shadows • The Applied Go Weekly Newsletter 2024-06-02
Your weekly source of Go news, tips, and projects
Curiosity skills the cat!
Usually, hardware speed improvements cannot be emulated by software on older hardware. Because without the new kind of hardware acceleration, how should software become faster?
Here is an example where hardware acceleration actually leads to faster software just by emulating the hardware technique.
The first article in our Featured Articles section describes a re-implementation of shadow stacks, a feature in modern x86 processors, in Go for speeding up stack trace capturing. While not enjoying hardware support, software shadow stacks can make Go's frame pointer unwinding faster than the current implementation.
The overall speedup is not that earth-shaking, but this article is another example of getting interesting insights from sheer curiosity.
Blazingly Fast Shadow Stacks for Go
Go's stack trace capturing could be eight times faster, if it was working in the shadows...
Blazingly Fast Shadow Stacks for Go
Alternatives to Makefiles written in Go
make
is the grand dame of build tools. It exists on every unix system and is therefore the number one choice for many projects. Still, make
has quite some quirks, especially regarding the syntax and behavior of Makefile rules. Spaces are relevant, and rebuilds are determined by the change date of a file, to name only two details that make developers look for better alternatives. Two hot contenders, specifically for Go projects, are Taskfile and Mage.
Alternatives to Makefiles written in Go
Go Error Propagation and API Contracts | matttproud.com (blog)
Should an error be simply returned or wrapped in a new error? Matt T. Proud suggests returning errors verbatim unless the caller is in another (architectural) domain. To wrap the error in a higher-level error, you can choose between sentinel errors, struct-based errors, and opaque errors.
Go Error Propagation and API Contracts | matttproud.com (blog)
Podcast corner
Cup o' Go: Go, meet hugging face 🤗, interview with Riccardo Pinosio
Hugging Face is a collaboration platform for the machine learning community. Jonathan and Shay have Riccardo Pinosio with them to talk about Hugging Face andhugot
, the "Huggingface transformer pipelines in Golang".
Go Time: Your ultimate guide to mastering Go featuring Samantha Coyle (Go Time #317)
A new Go programming book has been published. The author, Samantha Coyle, joins Angelica to talk about the book.
Backend Banter #055 - Talking Go with the Go God ft. AnthonyGG
AnthonyGG is probably best known from his Youtube videos about Go. In this episode, he talks to Lane Wagner about his backstory, database migrations, ORMs, and more.
Go tip of the week: Domains for local dev servers
I have a bunch of servers running locally, and I find it quite inconvenient (and inelegant) to access them as localhost:8081
, localhost:9000
, and so forth.
With Caddy, the amazing Web server written in Go, setting up "domains" for local servers is easy as pie.
Let's say you have a local server listening on port 9000. After installing Caddy, run
caddy reverse-proxy --from myserver.localhost --to :9000
and open https://myserver.localhost
. Boom: your server at localhost:9000
answers!
Note the https
protocol — Caddy even provides local TLS certificates. (Caddy generates and installs a CA root automatically on first invocation; you might have to enter your local user's password if the OS asks you to. And you might have to run caddy trust
. I tested on macOS with a non-admin user with sudo
privileges, and I did not need caddy trust
, but your mileage may vary.)
If you want to proxy more servers this way, create a file named Caddyfile
and enter host configuration like so:
myapp.localhost {
reverse_proxy :9000
}
myhugoblog.localhost {
reverse_proxy :1313
}
Repeat this pattern to add local servers as needed.
Then run
caddy
in the directory where you created the Caddyfile.
That's it! No messing around with DNS entries or TLS certificate files.
Quote of the week: Bad code
If you're not writing bad code, you're not learning anything.
More articles, videos, talks
Implementing React-like Composition using Go's html/template
Can Go's "no-BS philosophy" (author) bring React's core concepts to new life, free from the JavaScript baggage that accumulated over the years? Sheshbabu Chinnakonda thinks so and built a PoC.
The long-overdue problem coming for some people in Go 1.23
Do you use the //go:linkname
directive in one of your projects? Be prepared to see this directive being marked as deprecated in Go 1.23.
What's bad news for you is probably good news for others. This directive basically allows code to import unexported identifiers (only in the context of unsafe
, but still…). This can lead to weird error messages that are difficult to track down.
(Follow-up article here.)
Abusing Go's infrastructure | Reverse Engineering
Why does the Go sum database list entries for repositories that contain zero Go code? How did they get there? If anyone can fill the Go proxy with arbitrary data, doesn't this call for abuse? An investigation.
Exploring Middlewares in Go
Want to write HTTP middleware? In JavaScript, you have express
. In Go, you have net/http
.
A primer.
(Mostly) Deterministic Simulation Testing in Go
There should be very few occasions where a project requires a modified Go runtime. For deterministic testing, the Polar Signals team needed to remove any source of randomness from their Go app. They achieved this by using WASM to force single-threaded execution, modifying the Go runtime to get predictable random number generation, and the faketime
tag to activate the fake time feature used by the Go playground.
How to do Data Serialization and Deserialization in Golang
Data serialization and deserialization for six serial data formats.
Projects
Libraries
GitHub - creativecreature/sturdyc: A caching library with advanced concurrency features to help you build highly performant and resilient applications.
The cache is purely in-memory but can be paired with a distributed key/value store. The author uses this library for running a cost-effective memcache alternative.
GitHub - kevincobain2000/go-progress-svg: Generate pure SVG circle progress bar or flat progress bars in GO.
Need some nice-looking progress meters in your (server-side-rendered) Web app? This package generates either of the two as SVGs.
ssm package - git.sr.ht/~mariusor/ssm - Go Packages
In my early days of programming, I once created an ad-hoc state machine to avoid getting into nested if-then-else hell. Just sayin', in case you wonder if state machines have real-world use cases.
GitHub - rhartert/gofzn: Parser for the FlatZinc modeling language in Go
FlatZinc is a machine-friendly subset of MiniZinc, a high-level constraint modelling language for solving discrete optimization problems. If you need to model complex tasks like vehicle routing, staff rostering, or resource planning in Go, this package may come in handy.
Interesting detail: Its tokenizer is inspired by Rob Pike's talk "Lexical Scanning in Go".
GitHub - gekatateam/mappath
JSON handling can be frustrating. In the ideal case, the JSON structure is well-defined so that you can unmarshal JSON data into a struct. But if the JSON data is "dynamic", in other words, can have different structures in an unforeseeable way, your best bet is to sacrifice type safety and continue to treat the unmarshaled data as dynamic data. This library lets you work with such dynamic structs by using dynamic access paths, like person.name.first
.
Tools and applications
GitHub - Permify/permify: Open source authorization service inspired by Google Zanzibar to build fine-grained and scalable authorization systems.
Note that this article is a proof of concept and thus doesn't necessarily include all possible secrity measures (such as crypto.subtle.ConstantTimeCompare
instead of string.Compare
).
GitHub - f01c33/enc-pad: Encryted at rest file editor
Enc-pad encrypts the files it creates. As with every app using encryption, treat it as a PoC until it has undergone a professional security review.
GSA TreeMap
go-size-analyzer
, or gsa
for short (see the newsletter issue from 2024-04-28), now has a Web service. Analyze the size of a Go binary in your browser, no need for installing gsa
.
GitHub - mehran-prs/snip: A simple and minimal command-line snippet manager
Manage command-line snippets, with fzf
(Fuzzy Find) integration.
Completely unrelated to Go
Instead of "auth", we should say "permissions" and "login"
Half of the dev world is constantly getting confused about "authentication" versus "authorization". That's why I absolutely subscribe to Nicole Tietz' point of view.
9 Unexpected Profiling Use Cases Beyond Performance Optimization
Profiling is for improving performance, right? Not so fast! (Pun intended.) Felix Geisendörfer knows nine more reasons to dig into execution profiles.
Writing a Unix clone in about a month
I bet Drew DeVault (of Sourcehut fame) felt a bit like little Linus Torvalds when he wrote Bunnix.
Happy coding! ʕ◔ϖ◔ʔ
Questions or feedback? Drop me a line. I'd love to hear from you.
Best from Munich, Christoph
Not a subscriber yet?
If you read this newsletter issue online, or if someone forwarded the newsletter to you, subscribe for regular updates to get every new issue earlier than the online version, and more reliable than an occasional forwarding.
Find the subscription form at the end of this page.
How I can help
If you're looking for more useful content around Go, here are some ways I can help you become a better Gopher (or a Gopher at all):
On AppliedGo.net, I blog about Go projects, algorithms and data structures in Go, and other fun stuff.
Or visit the AppliedGo.com blog and learn about language specifics, Go updates, and programming-related stuff.
My AppliedGo YouTube channel hosts quick tip and crash course videos that help you get more productive and creative with Go.
Enroll in my Go course for developers that stands out for its intense use of animated graphics for explaining abstract concepts in an intuitive way. Numerous short and concise lectures allow you to schedule your learning flow as you like.
Christoph Berger IT Products and Services
Dachauer Straße 29
Bergkirchen
Germany