The Applied Go Weekly Newsletter logo

The Applied Go Weekly Newsletter

Subscribe
Archives
February 4, 2024

Memory bloat? Do this. • The Applied Go Weekly Newsletter 2024-02-04

AppliedGoNewsletterHeader640.png

Your weekly source of Go news, tips, and projects

Whew! Two strange and busy weeks are now behind me. Two weeks of testing and tweaking, talking to tech support, tweaking again, weighing pros and cons, and finally deciding to move away from my mailing provider. Going forward, I send this newsletter via Buttondown.email. There are still a few quirks to be addressed, but overall I am super happy with the service.

  • I can go much quicker from collecting news to finishing the draft, thanks to Buttondown's Markdown support.
  • The newsletter now has a public archive (although I plan to build a separate one on appliedgo.net that includes all the past newsletters that would otherwise have been buried on my previous mailing platform that did not provide a public newsletter archive).
  • And the newsletter has an RSS feed, for anyone who wants to subscribe without subscribing.

Talking about quirks, you might have noticed a "premium subscription" link at the bottom of the post. I played with Buttondown's features and enabled paid subscriptions, but I was not aware that this is a one-way change. I was unable to switch off the setting before sending that issue, but Justin and his team disabled that setting quickly and filed a fix. So everything is back to normal, and I am left being impressed by their swift support.

One of the next issues might already get sent via the API, removing another manual step from the process. Buttondown works so much better for my workflow, I don't know why I did not make the switch earlier.

(If you want to try out Buttondown, use this referral link to get $9 off the first month.)

But back to business, we have a lot of Go news to go through.

Go Memory Metrics Demystified | Datadog

Analyzing memory usage in Go is trickier than you may think. Felix Geisendörfer discusses the various approaches for collecting and analyzing memory metrics, from runtime/metrics to goroutine profiling.

Go Memory Metrics Demystified | Datadog

Type assertion vs type switches in Go

At least, Go has no type casts! Redowan Delowar is tired of asking LLMs over and over again about type assertion vs type switches, so he wrote down the essence of these. (Ironically, it's probably only a matter of time until LLMs digest this article into their digital neurons.)

Type assertion vs type switches in Go

What’s New in Go 1.22: slices.Concat

Another insider post about new features in Go 1.22. Carlana Johnson describes how she proposed and implemented slices.Concat().

What’s New in Go 1.22: slices.Concat · The Ethically-Trained Programmer


Podcast corner

Cup o' Go

Jonathan Hall and Shay Nehmad about Go 1.22RC2, the Go developer survey, Go Changes, two CLI tools, and one library.

Cup o' Go | A bunch 🍇 of grape things are happening

Go Time

Neil S Primmer & Benji Vesterby organized the Go Capture the Flag event ("a scavenger hunt for nerds") at GopherCon 2023.

Go Capture the Flag! 🚩 with Neil S Primmer & Benji Vesterby (Go Time #301) |> Changelog


Go tip of the week: How to get build information of a Go binary

A really quick one this week:

You surely know the command go version that returns the version of the installed Go command.

Here is another way of using it. If you pass the -m flag along with the path to a Go binary, go version lists the Go version used to build the binary, the dependencies, and the build flags used.

Like so:

> go version -m $(which gopls)         0s
/Users/christoph/.go/bin/gopls: go1.21.5
        path    golang.org/x/tools/gopls
        mod     golang.org/x/tools/gopls        v0.14.2 h1:sIw6vjZiuQ9S7s0auUUkHlWgsCkKZFWDHmrge8LYsnc=
        dep     github.com/BurntSushi/toml      v1.2.1  h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
        dep     github.com/google/go-cmp        v0.5.9  h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
        dep     github.com/sergi/go-diff        v1.1.0  h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
        dep     golang.org/x/exp/typeparams     v0.0.0-20221212164502-fae10dda9338       h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
        dep     golang.org/x/mod        v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
        dep     golang.org/x/sync       v0.4.0  h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
        dep     golang.org/x/sys        v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
        dep     golang.org/x/telemetry  v0.0.0-20231114163143-69313e640400       h1:brbkEFfGwNGAEkykUOcryE/JiHUMMJouzE0fWWmz/QU=
        dep     golang.org/x/text       v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
        dep     golang.org/x/tools      v0.14.1-0.20231114185516-c9d3e7de13fd    h1:Oku7E+OCrXHyst1dG1z10etCTxewCHXNFLRlyMPbh3w=
        dep     golang.org/x/vuln       v1.0.1  h1:KUas02EjQK5LTuIx1OylBQdKKZ9jeugs+HiqO5HormU=
        dep     honnef.co/go/tools      v0.4.5  h1:YGD4H+SuIOOqsyoLOpZDWcieM28W47/zRO7f+9V3nvo=
        dep     mvdan.cc/gofumpt        v0.4.0  h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
        dep     mvdan.cc/xurls/v2       v2.4.0  h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
        build   -buildmode=exe
        build   -compiler=gc
        build   DefaultGODEBUG=panicnil=1
        build   CGO_ENABLED=0
        build   GOARCH=arm64
        build   GOOS=darwin

HT to Jonathan Matthews.


Quote: Switch your ecosystem

Programmers must switch ecosystems at least once or twice in their career to gain truly “senior” experience. We’d all be better off if every JavaScript developer would work with Go for a year and then come back, every TypeScript developer with Ruby, every Ruby developer with Rust, and so on.

– Thorsten Ball


More articles, videos, talks

Beginner's Guide to Redis with Go! - YouTube

Get a crash course about Redis with Go from Elliot Forbes. In 11 minutes from zero to Redis.

Client-side pagination in Go (range-over function edition) - Vladimir Varankin

Vladimir Varankin uses the rangefunc experiment to refine his generic iterator that he made in 2022 for implementing client-side pagination.

Fun with Adaptive Rate Limiting

Based on a practical implementation for OpenZiti, Paul Lorenz explains how adaptive rate limiting helps minimize wasted work and maximize throughput across all requests.

Integration Testing In Go Using Testcontainers

Unit testing is baked into Go. Integration tests need to take the surroundings into account and hence aren't that straightforward. Shaibu Shaibu explains how to run integration tests in a scenario with a Go CRUD service, a Redis cache, and a PostgreSQL database using testcontainers.

How Disney Hotstar Captures One Billion Emojis! - YouTube

How do you manage five billion(!) emoji reactions during a Cricket World Cup event? With Go, of course. To be fair, some credits also go to the distributed and scalable architecture.

Using Gemini models in Go with LangChainGo

Accessing Go's Gemini AI models from Go is now possible via LangChainGo. – By Eli Bendersky.


Projects

Libraries

gaissmai/bart: The Balanced Routing Table is an adaptation of D. Knuth's ART algorithm combined with popcount level compression and backtracking. It is somewhat slower than ART, but requires considerably less memory.

Don Knuth's Art of Computer Programming isn't outdated at all. His Allotment Routing Table algorithm has been re-implemented in Go by Tailscale, which inspired Charly Gaissmaier to build a balanced version of ART with much lower memory consumption.

GitHub - hyperioxx/goexcel: goexcel is a Go library focused on facilitating basic Excel file operations. It's particularly useful for projects that need to handle Excel files with simple computational and logical functions.

Manipulate Excel sheets with Go. WIP.

GitHub - maxnorth/nv: A .env loader with secret manager integration

Don't put secrets in environment variables or .env files. With nv, environment variables can hold URLs to secret values, and nv will invoke the appropriate secrets manager's CLI command to fetch the actual secret.

GitHub - stephanrotolante/go-lang-jpg-analyzer

When was the last time Rob Pike commented on your work? TIL: If something is already in the stdlib, this does not mean that it should not be re-implemented for fun and learning.

Tools and applications

GitHub - danvergara/morphos: Self-hosted file converter server

If you need a hosted file conversion service but want to stay away from 3rd-party services due to privacy concerns, here is an alternative for self-hosting.

GitHub - semanser/tinygo-wasm-webgl-demo: A basic tinygo-wasm-webgl demo

Is Go a good fit for Webassembly? The author of tinygo-wasm-webgl-demo thinks so. "I wanted to try running Go in the browser and came up with a very simple demo. I used the default Go compiler at first, but the .wasm file size was around 2MB. Surprisingly, switching to TinyGo didn't require any changes at all. It just worked, and as a result, the total .wasm bundle size is only 170kb now.

"Honestly, I'm surprised how good it is since everyone is only talking about Rust + Wasm combo. Will definitely continue to experiment more."

GitHub - Assifar-Karim/cyclomatix: A static analysis tool for Go that generates control flow graphs and computes cyclomatic complexity

How do you measure the complexity of source code? A possible way is to calculate the Cyclomatic Complexity, which is a quantitative measure of the number of linearly independent paths through a program's source code.cyclomatix is a tool that analyzes Go source code and produces a control flow graph in GraphWiz format.

GitHub - lba-studio/n-cli: ✉️ Send notifications - Discord, Slack, desktop, whatever - through your terminal.

Get notified via Slack or Discord when a long-running command finishes.

GitHub - codomatech/goprep: Programmable REverse Proxy in Go. Modify responses in a Python-like language.

...where the Python-like language is Starlark.

GitHub - paulsonkoly/calc: Small functional language implemented in go

To write a compiler, you would typically reach out to the usual tools: lexer, parser, and so forth. Paul Sonkoly, not so much. Instead, he wrote a small functional language in Go with his bare hands, from scratch.

GitHub - ufukty/gonfique: Makes working with type checked configs easier for Go developers by providing struct type definition for given YAML file

The idea: Generate config structs from YAML files. Advantage 1: Easily stay up to date with changes to the YAML structure. Advantage 2: Avoid search operations like cfg.Find("A").Get("B") and use type-safe access like cfg.A.B.

GitHub - cel7t/TileEx: A Tiling Pattern Extractor written in Go

The art of making a tiled wallpaper is to disguise the edges of the base tile. The wallpaper then looks like a single, large pattern. This app extracts the base tile of PNG wallpapers and helps you uncover the secrets of their patterns.


Completely unrelated to Go

Sometimes, the choice of language DOES matter.

"No way to prevent this" say users of only language where this regularly happens - Xe Iaso

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.

Check it out.


Christoph Berger IT Products and Services
Dachauer Straße 29
Bergkirchen
Germany

Don't miss what's next. Subscribe to The Applied Go Weekly Newsletter:
LinkedIn
This email brought to you by Buttondown, the easiest way to start and grow your newsletter.