(RTs massively appreciated)
When I started byteSizeGo, I always wanted it to be bigger than just me. Over the past few months it has been a pleasure to partner with
@mmontagnino
and I'm so excited that her course The Art of Command Line Interfaces is nearly ready for launch!
Not a
#golang
specific tip, but people often give the advice "the best way to get better at any programming language is to write more programs". This is true at the start, but as you begin to get more comfortable with the language, the best way to improve is to read lots of other
@soren_iverson
It could increase the longer it goes unpressed so it becomes a game of chicken. Similar to when airlines need you to volunteer to get off and they keep increasing the voucher
The
@golang
team have been on fire and yesterday the published a blog titled "Perfectly Reproducible, Verified Go Toolchains". Here are the highlights:
- Software is often distributed in binaries, which can be difficult to inspect.
- We want to protect our software from Supply
Building a
#golang
container image for production
One of the many reasons I love GO is how easy it is to build and containerise. However, it's also important to ensure your production application has the smallest attack surface possible, is portable, and small in size.
Let's
Functional Options Pattern in Go
The functional options pattern in Go offers a flexible and readable way to configure your structs without exposing internal fields.
It is particularly useful when you want to provide optional configuration and there may be more configuration
I miss working at places with random server names for pre-production.
“Yeah you can test that on yoda1”
“We just promoted that to milhouse360”
“Ffs who broke Goldeneye?!”
Do you have any cool server names where you work or at home?
gRPC & Go
You have probably heard of gRPC if you haven't used it. It is particularly popular for inter-service communication due to its efficiency, language agnostic nature and support out of the box for things like MTLS.
Here's a really simple example of how you can get
(RTs appreciated).
I am very proud to announce that my first book is now available on Amazon!
UK link:
US link:
This really has been a labour of love for the past year, and I hope you enjoy reading it as much as I did writing it!
Why Context Should Probably Be the First Argument in Most of Your Go Functions
In
#golang
, the context package plays a big role in controlling the lifecycle of your code, especially when it comes to handling timeouts, cancellation signals, and passing request-scoped values. If
Singleflight
Singleflight is a really interesting package that "provides a duplicate function call suppression mechanism."
Why use singleflight?
Consider an application that fetches data from an API or a database (i.e, pretty much any application in existence). If several
A Brief History of Dependency Management in Go
For those of you newer to
#golang
, it might surprise you to know that go modules was not always part of the language. When Go launched in 2009, it did not have any dependency management solution as Google had no need for one.
As Go
If you spend time debating on pull requests whether the code you have written is idiomatic or not, consider creating a style guide that can be used as a point of reference.
If you are not sure where to start, start with Ubers: and then make changes to
errGroups are probably my favourite
#golang
package.
errGroup makes it really easy to take a bunch of tasks and run them in parallel, making your program faster. They do this whilst keeping your code readable.
Here's an example of one of my most common use-cases I asked
@SoVeryBritish
The free bag of Prawn crackers you got as well as the ones you ordered as you weren’t sure if you were going to get free ones and didn’t want to risk going without.
Garbage Collection in Go
For most of us, garbage collection is something we have heard of but never need to pay attention to.However, one of the reasons
#golang
is so efficient and easy to learn is due to its excellent GC.
What is Garbage Collection?
Garbage collection is the
Here's a cool little
#golang
trick. You can add something like the following:
to the top of your code to force a compile time check that a struct satisfies an interface. If it doesn't you'll see an error such as:
You shouldn't need to do this all the time, but let me tell you
I have two exciting pieces of news to share!
Firstly, I have taken on additional responsibilities at
@Cloudflare
and will now be responsible for Developer infrastructure as well as Developer productivity going forward.
Secondly, I'm hiring!
The spec says remote US, but I'm
Functional Options Pattern in Go
The functional options pattern in
#golang
offers a flexible and readable way to configure structs without exposing internal fields.
It is particularly useful when you want to provide optional configuration and there may be more configuration
An underrated way to attract great engineers to your company
(drumroll)
Have a great engineering blog.
This means ENGINEERS write the blog, not content writers. And they give the "real deal" about challenges, learnings, failures.
So few companies do this. A few that do:
Did you hear about the one billion row challenge?
It was intended to be a fun exploration of how far modern Java can be pushed for aggregating one billion rows from a text file.
So what happens when you try and do the same challenge in
#golang
?
@shraddhaag
expores exactly
Here is a quick example of the new context.WithCancelCause introduced in
#golang
1.21.
The output of the below program is "error from cancel func"
So why is this useful?
Previously if the context was canceled you either would not get an error back or you would get "Deadline
New Blog Post From the
@golang
team: Fixing For Loops in Go 1.22
You can read the original blog post here: , summary below.
The problem
The below should print a,b,c right?
It will actually print c,c,c. This is due to
Its also
Retweets massively appreciated.
Today, I'm excited to announce the waitlist for my first ever course, The Ultimate Guide to Debugging in Go.
Debugging is probably the most important skills that you never get taught. It is usually the first thing I teach folks and it's often
Being a generalist isn’t a bad thing, and a lot of teams at
@Cloudflare
interview for this trait. We love hiring folks who say things like “I don’t know how it works, I used it on this project though and this is what I observed” or “ I don’t know how it works but here is how I
Lots of people use the “Jack of all trades, master of none” in a degrading manner.
A reminder that the full saying is this:
“Jack of all trades, master of none,
Oftentimes better than master of one.”
It’s how it’s meant to be used and quoted if you do :)
GOMAXPROCS
There is an environment variable (GOMAXPROCS) that you can set which determines how many threads your go program will use simultaneously.
You can use this great library from Uber() to automatically set the GOMAXPROCS variable to match a Linux
I just wrote my ambitious
#golang
blog post yet!
It has taken me weeks to put together; this blog post had me going through my bookcase, all the bookmarks I have made since 2018 and watching 10s of hours of YouTube videos and courses. I really hope it is useful to you!
It has a
Here's a cool use for a
@Cloudflare
worker:
- Check the header to see which platform you open the link on
- direct you to the correct App Store.
- Fall back to your website if you can't figure it out.
This means you can share one link with folks to download your app.
If you’re looking for your next role in
#golang
, I made a small test repo for you to practise on:
It’s a simple CRUD application but it has lots of smelly code, some security issues and poor design choices. Can you spot them all?
Awesome new
#golang
blog on traces:
The blog highlights several key enhancements in Go's execution traces, focused on the runtime/trace package. Here's a summary:
- Prior to Go 1.21, the run-time overhead of tracing was somewhere between 10–20% CPU for
Return early, return often
One of the idiomatic practices in
#golang
programming is the concept of "return early, return often."
Rather than deeply nesting code, which can lead to "arrow code" shape, Go encourages developers to handle conditions (especially errors) and return
Go 1.21 is going to be released sometime in August, and comes with a few nice editions. Here's my highlights:
- min and max functions
- More specific import ordering
- The new go test option -fullpath prints full path names in test log messages, rather than just base names.
-
Re-sharing this.
This repo contains Golang code that does not follow best practises, contains bugs and security issues. It is intended to be used as an interview exercise or a practise exercise for jr/mid-level
#golang
engineers.
This repo contains, technically, a functional
To celebrate reaching 5k followers,
@PacktPublishing
have kindly provided 3 copies of my book Domain-Driven Design with Golang to give away for free!
To win, all you have to do is either like or repost, and reply with your favourite
#golang
library and why. Feel free to promote
Backwards Compatibility, Testing Changes to the Go Language and GODEBUG
Yesterday a blog post by
@_rsc
was released on . The post is well worth a read but here is a summary of my key takeaways:
- The
#golang
team takes backwards compatibility really
Pointer vs Value Receivers
First long-form
#golang
tweet of 2024 :)
When mentoring folks, we usually pause for a little bit to talk about the difference between these two.
Here's an example pointer receiver:
When you use a pointer receiver in a method, you're working with the
I just published a new blog called “How I keep myself alive using Golang”. It’s an adaption of the talk I gave at Gohpercon Singapore this year. I hope you enjoy it and learn a lot about a pretty unique use case for
#golang
Thanks to
@shraddhaag
for proof-reading and for the
Go Build Tags
Did you know you can include comments
#golang
in files that determine whether a file should be included during the build process?
For example, the following simple code:
will be excluded from builds except on Linux, unless we explicitly pass the build flag.
You
@SoVeryBritish
Dr: “how are you?”
Me: “Yeah good, you?”
Dr: “fine yes, how can I help?”
Me: “I don’t want to cause a bother but my leg seems to no longer be attached to my body, could you take a look if it’s not too much trouble? It’s fine if not, sure it will be fine”
Should UUID be part of the
#golang
standard library rather than us all importing 3rd party projects?
Is it just me or do you use them on pretty much every project?
(Retweets hugely appreciated)
To celebrate the release of Go 1.22, I put together a FREE course to teach you about the major changes in go 1.22 in JUST 22 minutes! You can check it out here:
Let me know what you think!
Its all a little Fuzzy...
In
#Golang
1.18, support was added for Fuzz testing.
Traditional testing methods, like unit tests, are limited by your own foresight.
Fuzzing, on the other hand, can uncover unexpected issues by bombarding the program with a vast range of inputs,
There is a nice set of
#golang
books available on humble bundle this week from some amazing authors and one less awesome one (me)
You can grab them here:
When to use Generics in
#golang
Adding Generics to Go was a controversial thing to do, and remains so to this day. They have been a huge quality of life improvement for some use cases, but in many instances I have seen them used as too early an abstraction and make code harder
Just Build Something!
It might seem counterintuitive, but one of the the best ways to grow as a software Engineer, even if you want to specialise in Backend or
#golang
, is to build full stack side projects, especially if it means using other languages.
Why?
Every language has
its official;
#golang
twitter loves sqlc!
What is it?
sqlc generates type-safe code from SQL.
- You write queries in SQL.
- You run sqlc to generate code with type-safe interfaces to those queries.
- You write application code that calls the generated code.
Here's an example.
Go Embed
The Ability to embed file into your
#golang
binary was added in Go 1.16. It's really easy to do and really powerful. Let's take a look.
As you can see, all we need to do is add what looks like a comment. Comments that start //go: are called compiler directives. You
Sorted!
#Golang
provides a sort package which by default allows you to sort primitives, but can be extended to sort anything!
Firstly, primitives:
You can also check to see if a list is sorted:
And if you want to, in reverse order:
Finally, you can can satisfy the Sort
Great to see that is being revived! It has always been a stable, idiomatic and sensible router to me and I have struggled to find one that I liked as much since it was archived.
(Likes and Retweets massively appreciated!)
Today I'm proud to announce the launch of my course: The Ultimate guide to Debugging in Go !
Being able to debug locally and in production is a critical skill for any Go engineer, but it is rarely taught explicitly....until now!
For
Profile-guided optimization in Go 1.21
The
@golang
team really are doing amazing work with blogging lately. Yesterday they released a blog titled "profile-guided optimization in Go 1.21"(). Here's a TLDR and why you should care:
- PGO works by leveraging
I mentioned on a podcast with
@goinggodotnet
a few months ago that I was trying to train a model to answer questions on
#golang
that would help others learn by directing them to (at least what I believe to be) good resources. I stopped working on this as progress was slow and it
I wrote another
#golang
blogpost on go workspaces; one of the lesser shouted about features of go 1.18 but incredibly useful! You can read what workspaces are and how you can use them here:
@Cloudy_Judgemnt
@elonmusk
@sampullara
This is absolutely not the correct way to do it. There are much simpler and safer ways to discover if services are being called, how often and in what user flows.
Every time I see people complaining about Go, it’s from people who say the error handling is too verbose and they find it confusing/hate it and are going to go back to Java/C#/php
If you feel this way, I challenge you to stick with it for 30 days and then let me know if you feel