This article presents Mugo, a single-pass compiler for a tiny subset of the Go programming language. It outputs (very naive) x86-64 assembly, and supports just enough of the language to implement a Mugo compiler: int and string types, slices, functions, locals, globals, and basic expressions and statements.

This post is a basic introduction to running HTTPS servers and clients in Go using TLS. It assumes some familiarity with public-key crypto. Feel free to check out my earlier posts about RSA and the Diffie-Hellman Key Exchange; TLS uses the elliptic-curve version of Diffie-Hellman. I won’t be covering how the protocol itself works in detail here, but if you’re interested I recommend to read up on the subject.

No software is perfect, and thus even for software I find very pleasant, I can usually identify some problems in it — often using my blog to do so. Even my all-time favorite software project, Plan 9, has some painful flaws! For some projects, it may be my fondness for them that drives me to criticise them even more, in the hope that they’ll live up to the level of respect I feel for them.

One such project is the Go programming language. I have had many criticisms, often shared on this blog and elsewhere, but for the most part, my praises have been aired mainly in private. I’d like to share some of those praises today, because despite my criticisms of it, Go remains one of the best programming languages I’ve ever used, and I have a great deal of respect for it.

Read More

I thought about this just before I went to sleep the other day, and the answer was more interesting than I’d imagined!

This post may be a little longer than usual, so grab your coffees, grab your teas and without further ado, let’s dive in and see what we can come up with.

All code snippets point to a stable reference; in this case to release-branch.go1.16.

Go modules are a fundamentally misguided and harmful change in the design of the Go ecosystem. I decline to adopt them or to use software which requires use of them.

Today the Go team is very happy to announce the release of Go 1.16. You can get it from the download page.

The new embed package provides access to files embedded at compile time using the new //go:embed directive. Now it is easy to bundle supporting data files into your Go programs, making developing with Go even smoother. You can get started using the embed package documentation. Carl Johnson has also written a nice tutorial, “How to use Go embed”.

Go 1.16 also adds macOS ARM64 support (also known as Apple silicon). Since Apple’s announcement of their new arm64 architecture, we have been working closely with them to ensure Go is fully supported; see our blog post “Go on ARM and Beyond” for more.

Note that Go 1.16 requires use of Go modules by default, now that, according to our 2020 Go Developer Survey, 96% of Go developers have made the switch. We recently added official documentation for developing and publishing modules.

Finally, there are many other improvements and bug fixes, including builds that are up to 25% faster and use as much as 15% less memory. For the complete list of changes and more information about the improvements above, see the Go 1.16 release notes.

Read More

If you haven’t worked in a typed language before, it may not be obvious at first the power that it brings. This article will show you how to leverage the type system to make your code easier to use and more reusable.

Recently, a colleague spent a bunch of time working on a bug. When attempting to perform some action, the system would provide feedback that everything was going as planned, and then “go dark,” seemingly out of no where. It’s important to realize that this is a complex distributed system, and that there is a network connection between the “part that worked” and “the part that went dark.” But, there wasn’t a change to the connection logic, and it worked before, so that “couldn’t possibly be it.”…

Read More

As the primary author of Python’s os.scandir function and PEP 471 (the original proposal for scandir), I was very happy to see that Go is adding something similar in Go 1.16, which is coming out in late February 2021.

In Go it will be called os.ReadDir, and was proposed last September. After more than 100 comments and several tweaks to the design, it was committed by Russ Cox in October. A file system-agnostic version is also included in the new io/fs package as fs.ReadDir.

One of the most common issues novice Go programmers run into is the inability to pass a slice of a concrete type (e.g. []int64) into a function that expects a slice of interfaces (e.g. []interface{} or something like []fmt.Stringer). Why is that?

In this post, I’m going to list several answers to this question, diving into some interesting implementation details of how Go works under the hood.

The upcoming Go 1.16 release has a lot of exciting updates in it, but my most anticipated addition to the Go standard library is the new io/fs and testing/testfs packages.

Go’s io.Reader, io.Writer, and os.File interfaces go a long way in abstracting common operations on opened files. However, until now there hasn’t been a great story for abstracting an entire filesystem.

Back in 2018, we compared empirically the performance overheads of Go and C++ with regards to the low-level calling convention: to pass arguments, to return multiple values, and when propagating exceptions.

Those results were obtained with Go 1.10 and Clang 6.0. Since then, compilers have evolved and we are now running with Go 1.15 and Clang 11.0. Have the findings changed since then?

The question of interest was:

What is cheaper: handling exceptions via panic / recover, or passing and testing error results with if err := …; err != nil { return err }?

In fact, as we will see below, the conclusions are stronger today than they were two years ago.

Read More

Today’s Go security release fixes an issue involving PATH lookups in untrusted directories that can lead to remote execution during the go get command. We expect people to have questions about what exactly this means and whether they might have issues in their own programs. This post details the bug, the fixes we have applied, how to decide whether your own programs are vulnerable to similar problems, and what you can do if they are.

Golang

Discuss the Go programming language.

Created on Oct 1, 2020
By @root