Try Go in Y Minutes • The Applied Go Weekly Newsletter 2024-03-31
Your weekly source of Go news, tips, and projects
You may have read about Codapi.org here one or two times. Codapi is a service for embedding runnable code snippets of almost any language into Web pages — and not only that: Recently, Anton Zhiyanov, the author of Codapi, created an interactive Caddy tutorial. You can fire up a Caddy web server with the click of a button and experiment with it!
Another new feature is the "Try X in Y minutes" series, which is like "Learn X in Y minutes" but with interactive code snippets.
Why am I writing this? Oh, yes — I earned some (really, just a few) bragging rights by contributing Try Go in Y minutes to the series! Most credits, of course, go to the authors of the original Learn Go in Y Minutes. (Both their and my article are CC-BY-SA licensed, in case you wonder.) I only changed and expanded a few descriptions, made the concurrency examples a tad bit simpler, and added generics. And, of course, I relentlessly ripped the original, monster-sized code sample into pieces and made them independently executable.
Too bad I can't embed Codapi code snippets in emails...
Blazing Fast GoLang Docker Builds | by Abhinav Sonkar | Mar, 2024 | ITNEXT
Does your dockerized Go project build step run waaay slower in the CI/CD pipeline than on your local machine? Abhinav Sonkar had this problem and found a surprising cause — and a solution.
Blazing Fast GoLang Docker Builds | by Abhinav Sonkar | Mar, 2024 | ITNEXT
Visual Guide to Slices in Go — Ozan Sazak
You have no chance to rule the (Go) world without knowing the internal mechanics of slices. The are not really difficult but may come unexpected to the Go newcomer.
Visual Guide to Slices in Go — Ozan Sazak
Data Flow Analysis for Go | The GoLand Blog
Interesting news for anyone who seeks doing static analysis with Go. JetBrain's latest GoLand version includes static code analysis that can warn of things like an assignment to a pointer variable that might still be nil at that point. GoLand is a commercial IDE, but you can try out the 2024.1 release candidate for 30 days.
Data Flow Analysis for Go | The GoLand Blog
Podcast corner
Go Time
Are you in the debugging-first camp? Or do you reach out to logging, printing, appliedgo.net/what, or other tools before spinning up the debugger?
Matt Boyle, Bill Kennedy, and Jon Calhoun discuss the pros and cons of debugging in the latest episode of Go Time.
Debugging with Matt Boyle & Bill Kennedy (Go Time #309)
Ardan Labs Podcast
From the Performing Arts to the tech industry, frontend programming, and Go. Rita Iglesias has quite a few things to share about her career.
Acting, Front End Dev, and Golang with Rita Iglesias
Go tip of the week: Why your version identifier should not contain uppercase letters
Did you know that you can query information about a Go module from a Go proxy server? A URL constructed as $base/$module/@v/$version.info
returns basic version information as JSON.
A while ago, someone reported an error with a specific Go module version. And it turned out that this error occurs if the module path contains an uppercase letter, like so:
https://proxy.golang.org/github.com/Sirupsen/logrus/@v/v1.9.3.info
bad request: invalid escaped module path "github.com/Sirupsen/logrus"
Likewise, if you query for a module with an uppercase letter in the version string (for example, v0.1.0-RC1
), the proxy server responds as follows:
bad request: invalid escaped version "v0.1.0-RC1"
The proxy does not like uppercase letters in module paths, and requires escaping those letters as !<lowercase-version>
, for example, !sirupsen
instead of Sirupsen
.
For go get
and friends, this escaping happens under the hood, but not for querying the proxy info.
This query works:
https://proxy.golang.org/github.com/!sirupsen/logrus/@v/v1.9.3.info
{
"Version": "v1.9.3",
"Time": "2023-05-21T12:59:35Z",
"Origin": {
"VCS": "git",
"URL": "https://github.com/Sirupsen/logrus",
"Ref": "refs/tags/v1.9.3",
"Hash": "d40e25cd45ed9c6b2b66e6b97573a0413e4c23bd"
}
}
Another reason for preferring lower-case URLs all the way.
Quote of the week: Traditional web apps
Mastodon is a testament to the fact that you can get quite far with a traditional webapp. There's no Kafka or Pulsar, Cassandra or Mongo, and no need for distributed consensus or cluster coordination.
More articles, videos, talks
How To Use Go and GitHub GraphQL API
The GraphQL API for GitHub is announced as being suited for more advanced operations, so if the GitHub REST API feels not up to the job, try the GraphQL API. With Dave "Squirvy"'s article, getting up to speed with that API should be no problem.
BCE (Bound Check Elimination) -Go 101
An introduction to Go's bound check elimination option.
If you love your SSH attackers so much that you can't let them go anymore...
Running Go code from Elixir Using Web Assembly - Yasoob Khalid
WebAssembly connects programming languages. This time, it's Elixir and Go.
Representing State as interfaces in Go
This is a clever idea: A struct method returns the struct as a different interface, to change the available method set. But then, there is this Go proverb: Clear is better than clever... I am sure there is a more idiomatic way to enforce status-dependent behavior. What do you think?
Goroutine leaks are subtle and hard to detect. Wouter Groeneveld shares an example of how to track down and fix a goroutine leak.
Projects
Libraries
GitHub - donseba/go-importmap: Golang importmap generator
If you are tired of fiddling with NPM for handling Javascript and CSS dependencies for your web app, try
go-importmap
.
GitHub - donseba/go-translator: Dynamic localization of applications
Make your apps multilingual!
go-translator
has enough features to make adding translation to an app a no-brainer.
Validate data from user input or other insecure sources.
GitHub - sugawarayuuta/charcoal: Faster utf8.Valid using multi-byte processing without SIMD.
How to make Go faster. Today's lesson: Speeding up
utf8.Valid()
.
Need more problems in your HTTP client? Use
problem-client
! Joking aside, this package "parses yourapplication/problem+json
HTTP response and returns the underlying members (if there exists) specified in RFC 9457 along with Extension Members also returned from the function."
How do you control log output? Using log levels can lead to missing diagnostic logs on a fatal event (so you have to replicate the whole error scenario, good luck with that). Sending all log output unconstrained to a log aggregator can eat up CPU time and disk space. This package sits between the two extremes. It keeps low-level log output in a backlog until a high-level log event triggers. Then it forwards the high-level event along with the backlogged low-level events to the log handler.
GitHub - calmdocs/SwiftPollManager
Embed a Go app in a SwiftUI app and let them communicate via HTTP long polling. A good alternative to writing an Electron app...
Tools and applications
GitHub - kg0r0/passkey-autofill-example: 🔑 Experimental implementation of Passkey Autofill in Go.
A demo/example app that lets you register a passkey and provides Passkey Autofill functionality when logging in.
GitHub - nickstambaugh/GOL: An Alternative to Conway's Game of Life, Simulated in Go
This happens when wind blows through the universe (if the universe in question is a Game Of Life matrix).
GitHub - dropdevrahul/hypr: A desktop application build using wails and Reactjs to perform REST APIs
Want to play with HTTP requests in a nice and simple UI?
hypr
is an interactive REST HTTP client using the Wails web UI project.
GitHub - nickstambaugh/rain-simulation: Simulating Rain Drops Using Raylib & Go
In the first milliseconds, my brain read "brain-simulation". Well, syntactically close but still wrong.
rain-simulation
is a small Go & Raylib app that you might want to run in fullscreen mode if it's just too sunny outside.
GitHub - charmbracelet/freeze: Generate images of code and terminal output 📸
From terminal to PNG in one command.
freeze
saves source code files, command output, or (with help oftmux
) even whole terminal screens to an image.
A data processing tool. Reminds me a bit of benthos.dev.
GitHub - danvergara/morphos: Self-hosted file converter server
A server for converting between images and PDF, and between PDF and DOCX.
Completely unrelated to Go
Chances are that you know GitHub Codespaces, and maybe you also heard of GitPod.io. Both are great ways to work on a repository in a dedicated, remote, and development environment.
GitPod is even open-source, but GitPod requires Kubernetes, and I failed to find documentation about self-hosting in the official docs.
But there are alternatives. Recently, I came across two alternative environments that are fairly easy to install and self-host: DevPod and Lapdev. Both use the Devcontainers spec for defining environments. Lapdev runs on Linux, whereas DevPod is available for Linux, macOS, and Windows.
So if you are looking for a self-hosted development container system, you might want to give these tools a try. (This being said, I still love the convenience of simply firing up a GidPod instance without installing or maintaining anything. But it's always good to have a choice.)
DevPod - Open Source Dev-Environments-As-Code
Lapdev - Self-Hosted Remote Development Environment
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