Go is like the Millenium Falcon • The Applied Go Weekly Newsletter 2024-05-05
Your weekly source of Go news, tips, and projects
Today — the day this newsletter has found your inbox — is the Revenge of the Fifth day, following the May the Fourth Be With You day.
Obviously, this weekend is in Star Wars mode. Which reminds me of the probably most famous spaceship ever, the Millenium Falcon. Did you know that this interstellar freighter is larger inside than it appears from the outside?
Sometimes, I feel the same is true for Go. From the outside, it's an apparently small language, but under the hood, it's a real powerhouse.
This newsletter surely isn't like Go or the Millenium Falcon. It's the same size from the inside and the outside.
But its appearance is not carved in stone. I wasn't happy about the comments on the articles in the More Articles section and the projects section, which I used to format as quotes. In this issue, I changed the links to headings and turned the comments into normal text. What do you think? Does it improve the reading experience, or worsen it, or is it the same?
Featured articles
Evolving the Go Standard Library with math/rand/v2
The Go Blog posted two articles this week! In the first one, Russ Cox inspects the reasons for the math/rand
package to evolve into a v2
(the first v2
package in the standard library, by the way). He concludes the article with transferring the observations into general principles for evolving the Go standard library.
Evolving the Go Standard Library with math/rand/v2 - The Go Programming Language
Secure Randomness in Go 1.22
Russ Cox and Filippo Valsorda examine the problem of generating randomness on a basically deterministic device — your computer — and the new cryptographic random number source in math/rand
.
Go is Not Java
Yes, this blog post is a rant. Yes, Jarrod Roberson does have a point. Design patterns were created for a specific language paradigm, and Go has a different paradigm.
A better CORS middleware library
Julien Cretel wasn't satisfied with the existing CORS middlewares and decided to build his own CORS packaage, with some distinct features.
jub0bs/cors: a better CORS middleware library for Go :: jub0bs.com
Go 1.22.3 and Go 1.21.10 pre-announcement
New Go patch releases will be out on Tuesday
[security] Go 1.22.3 and Go 1.21.10 pre-announcement
Podcast corner
Cup o' Go: Pick any number, but not like that! Bartek Nowotarski talks Go vulnerability research
This week's guest is Bartek Nowotarski, security researcher with a focus on protocols, programming languages, and popular open-source projects.
Pick any number, but not like that! Bartek Nowotarski talks Go vulnerability research
Go Time #314: Go workshops that work
If you plan a Go workshop, don't miss out on this episode.
go podcast() #036: Game UI in Go with EbitenUI maintainer Mark Carpenter
Games need a UI for setting options, selecting levels, and more. Mark Carpenter, the guest in this episode, created EbitenUI, a UI for the popular Go game engine Ebitengine.
Changelog and Friends #42: The Wu-Tang way with Ron Evans
The Go Time podcast is part of The Changelog. The current episode of Changelog and Friends includes some tiny bits of Go, or some bits of TinyGo if you will.
Pop quiz: What does this loop do?
If you know C++, you can surely tell what the loop in this code snippet does:
struct Foo {
int Value;
};
void f() {
std::vector<Foo> foovec;
//....
for (auto& foo : foovec) {
if (foo.Value > 10) {
foo.Value = 10;
}
}
//....
}
When the loop finishes, all Value
fields in foovec
greater than 10 will be set to 10. Because foo
is a reference, all changes to foo
go directly to the object it references.
Let's port this code to Go:
type Foo struct {
Value int
}
func f() {
var fooslice []Foo
//....
for _, foo := range fooslice {
if foo.Value > 10 {
foo.Value = 10
}
}
}
It's a rather straightforward rewrite, isn't it? If you have years of C++ under your belt and switch to Go, you would certainly write the loop like this. I would.
The problem is: The loop does not work as intended. Can you spot the problem?
Hint: Go defaults to pass-by-value semantics.
And this is the reason why the loop does not update fooslice
. The range
operator returns the current loop index (that is ingored by assigning to the blank identifier "_
") and a copy of the current element of fooslice
.
Assigning to this copy has no effect on the original slice.
To update fooslice
, the range
loop must access the slice element by its index instead:
for idx := range fooslice {
if fooslice[idx].Value > 10 {
fooslice[idx].Value = 10
}
}
(This Go Tip originates from Hal Canary's article Golang Pitfall.)
Quote of the week: I build things
Don’t be the person who says “I have strong opinions” because I promise you: everybody rolls their eyes when you say it. Be the “I build things” person instead.
– Thorsten Ball
More articles, videos, talks
ewen.works
So you invented a new nice programming language for which no language server exists? Roll your own!
Tokens for LLMs: Byte Pair Encoding in Go - Eli Bendersky's website
ERRATUM: The previous issue of this newsletter got the link wrong for this article. Here is the correct one.
Building a Search Engine from Scratch | HandcraftCode - YouTube
Christian De la Cruz wrote a search engine. In this video, he explains about everything you ever wanted to know about the inner workings of search engines. (Repo)
Talos built Sonic to reduce the time it takes to read and write data from the network with minimal latency
Speed up your network traffic: Sonic is an alternative (NOT a drop-in replacement) for the net
package, aiming at minimizing latency and jitter. The developer uses this package for building a trading app. Don't confuse talostrading/sonic
with bytedance/sonic
, a JSON (de-)serializing package. Repo here.
Golang error handling demystified. errors.Is(), errors.As(), errors.Unwrap(), custom errors and more – Adrian Larion
Surely not the first article on Go error handling, but this one is a well-written introduction to all aspects of Go's errors-are-values paradigm.
Encore Launch Week — The magic unfolds, explore a new launch every day
Even if you read this issue while it is still steaming hot, it might be too ambitious to join the hackathon organized by Encore and Golang Insiders — submission deadline is May 7th. But if you are fast and your brain spills over with ideas, this is your chance to win... a coffee machine! Yes, a coffee machine. But this one is not exactly a cheap one.
Using Nix to create reproducible Golang development environments | Haseeb Majid | Conf42 Golang 2024 - YouTube
Nix is a package manager aiming at providing reproducible environments. In this video from the Conf42 Go conference, Haseeb Majid meticulously explains what Nix is, how it works, and how you can create reproducible, ephemeral Go development environments with it.
jub0bs/cors: a better CORS middleware library for Go :: jub0bs.com
Some redditors stumbled over the phrase "...perhaps the best one yet." While this sounds like hubris, the author explained that this is meant to read as "...perhaps the best one I have written yet."
Mastering Maps in Go: Everything You Need to Know | HackerNoon
You know how to work with maps, but how do maps work?
GitHub - Elias-Gill/yt_player: Simple tui wrapper for the youtube API.
Listen to Youtube audio without a browser.
A Tale of a Suicidal Container | AI Logs
A Dockerfile was changed to multistage build, and the container instantly stopped working. Find the error.
An Applied Introduction to eBPF with Go | Edge Delta
Extended Berkeley Packet Filter, or eBPF, allows you to trace system calls, user space functions, and more. This article provides a brief introduction to eBPF and shows how to write an eBPF application in Go (with kernel-space code in C).
Show HN: Roast my SQLite encryption at-rest | Hacker News
ncruces/go-sqlite3
got an Adiantum encrypting VFS, which means encryption at rest. Here is the release.
Slashing Latency: How Uber's Cloud Proxy Transformed India's User Experience
How an engineer at Uber used the power of Go (and especially, Go's ReverseProxy) to whip up a working demo of a cloud proxy in 15 minutes (and about 120 lines of code) to fight TLS handshake latency that severely affected the user experience in India.
go.vallahaye.net/batcher
Asynchronous batch processing. Fill the batch queue until a certain size or time is reached, then the batch gets processed. Dead easy and no dependencies.
The (Hidden?) Costs of Vertex AI Resource Pools: A Cautionary Tale – P. Galeone's blog
Or: "The day my Vertex AI bill skyrocketed to 500% of the previous daily costs." A troubleshooting tale with Go code.
Dolt Gets a cgo Dependency
"Cgo is not Go", a Go proverb says. The Dolt team explains why they decided to add a CGO dependency to Dolt after having avoided the same for a long time.
Projects
Libraries
GitHub - oligo/gioview: Gio-view: A Toolkit for Faster Gio App Development
If you plan to write a Desktop UI app with Gio but miss the convenience of a widget library, check out Gio-view.
GitHub - invopop/ctxi18n: Go Context Internationalization - translating apps easily
Inspired by Ruby On Rails' i18n framework.
GitHub - zukeep/golang-signals
If you are missing SolidJS or Angular signals in Go, look no further. The author confesses to "have no idea why you would need to use it in your backend code. But now you can."
GitHub - rameshsunkara/go-rest-api-example: Enterprise ready REST API microservice in golang
An opinionated (Gin/zerolog/MongoDB) microservice example repository.
GitHub - 0verread/goralim: A rate limiting package for Go to handle distributed workloads
Your Go app is too fast? The downsteam services cannot keep up with its pace? Give them some rest with this rate limiter.
Tools and applications
GitHub - wkhere/bcl: Basic Configuration Language.
BCL is a configuration language similar but different to HCL, the Hashicorp Configuration Language. Features include direct marshaling to Go structs and rich expressions.
GitHub - igorhub/devcard: Devcards facilitate visual interactive programing in Go
Devcards is something between REPL and Jupyter Notebooks. Or maybe both at once.
GitHub - Rusty-Gopher/GoDBSniffer: CLI for checking MySQL health, performance and security status
Check your MySQL DB for health, performance, and security.
Godocument - Introduction
An HTMX-based clone of docusaurus.io, "giving it a SPA feel without diving into framework hell."
GitHub - Sieep-Coding/web-crawler: A simple web crawler implemented in Go.
A lightweight CLI app for crawling and scraping websites.
FUN with go stdlib – Sorting a slice of structs by multiple field values and really grokking it. – Adrian Larion
Sort like you never sorted before!
GitHub - hrishiksh/hash: A terminal based password manager for everyone
If a GUI is too heavyweight, a CLI tool too lightweight, take the Goldilock route and use a TUI — it'll be "just right".
GitHub - bigunmd/pgdmpres: Dump and restore Postgres backups
"A simple docker container with Go daemon that runs scheduled 'pg_dump'/'pg_restore' commands. Sync your staging database with relevant production database data. It can also be used just as a normal scheduled backup tool."
GitHub - theredditbandit/pman: A CLI project manager
Take this, Asana!
GitHub - farouqzaib/fast-search: Vector Database
A distributed vector database with full text search capability, written from scratch as an "academic"/self-learning project. Fun fact: The installation instructions start with a pip install
.
Completely unrelated to Go
Keynote: Thoughts on Open Source - Kelsey Hightower
What do the sleeves of a jacket have to do with open source? Kelsey Hightower knows how to make the connection.
A plea for free and open-source software in the face of recent events like Terraform's and Redis' moves from FOSS to BSL licenses.
How an empty S3 bucket can make your AWS bill explode | by Maciej Pocwierz
Not related to Go, but remotely related to the article about the exploding Vertex AI bill. The case here is different, though. AWS charges for unauthorized requests to S3 buckets, which caused an empty S3 bucket to collect $1,300 of fees within a day.
The Best Debugging Tool Rarely Used - by Kevin Naughton Jr.
A debugging tool available neither on anyone's disk nor online, yet everyone can use.
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