After 16 months of fostering my wife and I have officially adopted Danielle!
The journey here was challenging at times, but it was oh so worth it. Now I get to call her my sweet little daughter 🥰😍 Oh and I can finally share pictures of her!
🎉 I just released 🎉
Want to learn how algorithms and data structures work? Struggle with coding algorithms? Just want some fun coding problems while learning
#golang
? Check the course out!
And it is FREE! Yep, you heard me right. No💰 req for this one
You don't need to manually add struct tags to your
#golang
types. Almost all editors support some fort of struct tag generation, which is really handy. Multiselect can also do the trick if you are familiar with it.
If you use SQL and Go, how do you handle database migrations for your app? When do they run during a deploy, how are they rolled back, what tools, etc?
I still don't think I've seen anything as smooth as Rails was in a Go app. Figured I'd explore options again.
In 2022, I did this weird little experiment where I redesigned the net/http Handler in
#golang
. Rather than having a ServeHTTP(w, r) method, I instead broke it into two parts - a handler, and a responder that is returned from the handler. 🧵👇
My
#golang
courses are on sale until Oct 5.
- Web Dev w/ Go ()
- Test w/ Go ()
My free courses are still free 🤪
-
-
If you know someone learning Go, please let them know. Thanks!
Before
#golang
, I used to hate TDD. It just never worked for me. I doubt I practiced it perfectly, but it was hard to get into something that just didn't work for me.
I still don't use it all the time - maybe 50% - but when I do Go somehow makes it so much more enjoyable.
#golang
Generics make supporting useful zero values a bit simpler by giving us a way to quickly and easily determine what value to use - a default, or a provided value.
In the ex below, the Thing field can be set, or it can be left as the zero value and it will still work.
I finally released a mega-article on
#golang
code design, web apps, JSON APIs, and more (seriously, its like 40 pages 😱) that I've been writing for some time.
Feedback & sharing are both appreciated!
Dependency injection sounds scary complicated, but in Go it is usually as simple as using an interface as a function argument (or struct field) instead of a specific type. Don't let your experience in other languages worry you! 😁
New in
#golang
1.14 - testing.T's Cleanup() method.
Now any helper funcs can accept testing.T and handle both setup and cleanup. One example of this is when working with a test database, but really any functions designed to setup test resources could benefit from this.
I suppose now is as good a time as any to share the news. My wife and I will be adopting a baby boy who is due in early May. The backstory is kinda crazy, and I need to go back in time to when we adopted our first daughter for it all to make sense, but I'll share what I can. 🧵👇
This article is spot on. Errors in
#golang
feel painful b/c devs want to ignore errors. Go forces devs to acknowledge that something may go wrong and to code for it. Annoying at first, but I guarantee my Go code has better error handling as a result.
If you are confused about whether to use a pointer receiver or not in
#golang
, try asking, "Is there a good reason NOT to use a pointer receiver?" instead of "Should I use a pointer receiver?"
I may need to update my testing course soon! Go 1.14 added Cleanup, and now Go 1.15 looks to be adding TempDir!
With TempDir you can easily access a temporary directory for files used during testing. Best part? These are all cleaned up (deleted) for you automatically!
#golang
Fun fact:
#golang
has a zip package that can be used to create compressed zip files. This can be handy when you need to programmatically select files to move to a USB stick, upload to a server, or create a download for a user.
Working example at
If you are using interfaces in your
#golang
code, consider writing tests that accept any implementation of the interface. This helps sanity check all future implementations while also making sure you don't rely on poorly documented behavior.
I love this screenshot from the codebase. It just shows a bunch of
#golang
files all in a single package, yet the entire codebase still felt incredibly easy to understand and navigate.
My
#golang
courses are on sale until Jun 23.
- Web Dev w/ Go ()
- Test w/ Go ()
If you know someone learning Go who would benefit from one of the courses, please let them know! Thanks! 😁
Moving Towards Domain Driven Design in Go
#golang
This one took a while because it kept growing and evolving. I eventually had to accept that it needed broken into a few posts, and this one still ended up being huge.
Quick tip: If you record videos, share your screen, give talks, etc, create a second set of settings for VS Code (or whatever editor) that increases font size, etc. Then comment out the settings you don't want at any given time.
Using a run function makes
#golang
main packages much easier to test.
#vscode
default snippets don't do this, so I suggest creating a new one.
VSCode Snippet:
More on run func: by
@matryer
It can help me to think about concurrency as an assembly line. Each worker (goroutine) does a task, then sends the result along the assembly line (channel).
#golang
If you already have an account at you should see this now. Clicking the button will add it to your account. If you don't have an account yet, go to and sign up. I'll get the landing page + signup form for Algo w/ Go working tomorrow
I sat down this evening to re-record the sorting algorithm videos I released earlier, and wow. Already feeling 10x better about them. Pumped to get these released. And there are benchmarks now!
#golang
#Algorithms
If you want to be a full stack developer, you have to accept that you can't master every technology you will be using. Nobody can master frontend and backend and docker and a dozen others, but you can learn each well enough to be productive across the whole stack.
After 16 months of fostering my wife and I have officially adopted Danielle!
The journey here was challenging at times, but it was oh so worth it. Now I get to call her my sweet little daughter 🥰😍 Oh and I can finally share pictures of her!
The, "you don't need a CS degree" argument is crazy misleading.
It is true that you don't need a degree, but you better be ready to bust your ass and hope the stars align along the way. A thread...
/1
The builder pattern makes it really hard to return errors during a build step. Consider using functional options instead, which work much better with incremental errors.
#golang
Using JWTs in your
#golang
code? I would strongly suggest you add a test to verify the "none" signing method won't be accepted. This is a huge vulnerability that many people miss, and it is pretty quick to test.
My
#golang
courses Black Friday sale is live! 50% off any course or package.
Web Dev w/ Go -
Test w/ Go -
I only offer this discount once a year & it is a big part of my income, so all purchases & shares are appreciated 😁
Did you know that you can call methods directly from the type in
#golang
?
type Person struct {
Name string
}
func (p Person) Greet() {
fmt.Println("Hi, my name is", )
}
func main() {
p := Person{"Jon"}
Person.Greet(p)
}
When inserting records into a Postgres DB using Go's database/sql package, remember that the Result type's LastInsertId method isn't supported by most drivers. Instead, you need to write a query that returns the newly created record's ID and scan for it.
#golang
#postgres
#sql
My "Build a Blog with
#golang
" exercise series just keeps growing, but it is fun so I'm not complaining!
The next article walks through parsing metadata via frontmatter in preparation for showing a list of all blog posts. Check it out at
I want to see if I can create a
#gotime
episode discussing how people are using
#golang
generics. To do this I need your help.
Send me examples of generics in Go you have found useful. Could be something like options, a filter func, or whatever else.
When learning to code, it is important to realize that you can't just skip to the end. You can't write the code you will in five years without those five years of knowledge. There are ways to speed up the learning process, but you can't skip it entirely.
The last
#golang
email I sent to my mailing list went to over 40k subscribers and had an open rate over 50%! So pumped that people find these emails worth reading! 😃
If you missed it, it was a crash course on Go's generics.
I'm planning to offer a new years sale on my courses for anyone who wants to make a resolution to learn Go.
Super late to announce this. Dec has been brutal. I even have course updates I did a week ago that I haven't released yet :(
New to
#golang
? There are many ways to declare variables. A good rule of thumb is to use the var keyword when you plan to assign a value later and := otherwise. This way your intent is clearly expressed. Just remember there may be exceptions.
It is possible to transition into a tech career without a CS degree, but I think far too many people underestimate the amount of work it takes.
If it only took 3 months of coding 1 hour a day to land a job at Google their acceptance rate wouldn't be 0.2%
1/5
I know I haven't released anything in a while but I am busy making my free algorithms course while also working on a new site and outlining some ideas for an advanced
#golang
web dev course. It just may take some time until you see the results of all the work.
What are you using for
#golang
worker queues? Eg something like Sidekiq in Rails.
Message queues (like rabbitmq)?
Third party libs (like asynq)?
Custom code to manage it all?
Something else?
When using
#golang
pkgs like database/sql or image we import the _ packages for side effects caused by their init functions (see image below).
If writing a new lib, just have the user call Register themselves and provide them with a driver; it is much clearer what is happening.
Use io.MultiWriter when you need to write to two sources at once. This can happen when you want to capture what is being written without changing the behavior of existing code. I find this especially useful when running commands via the exec package.
#golang
Thank you for all of your support over the last week! It is still crazy to me that I have been able to help so many people 🤯
After taking some time to recover I'll be pushing more testing content and then starting on a new FREE course. I'm thinking algorithms in
#golang
I'm super late to announce this, but now has well over 10k students. In fact, it is very nearly 11k now 😱
Thanks everyone for checking out the
#golang
exercises and all the awesome feedback. I'm humbled to have helped so many ppl practice & learn Go!
The := syntax in
#golang
is great, but it can lead to variable shadowing unknowingly. Eg if you declare an error variable in the main block, but use := with multiple variables in a block, the err variable will be shadowed.
Next up in my Build a Blog with
#golang
series - rendering markdown as HTML. Read it here:
I'm looking forward to some of the content in the next few parts of the series, like adding support for custom markdown & reading files from GitHub.
Happy new year everyone!
2021 was a tough one for me, but here is to hoping 2022 is better. Goals for the year:
- Finish updating web dev w/ go
- Release a new course in the works
- Expand/update my free courses
- More beginner-oriented content
- More YouTube content
Interface chaining is crazy powerful when combined with simple interfaces like io.Writer in
#golang
. Take this example from oto () which adds gzip support without needing to change any additional logic in the function.
Need to write a custom json decoding logic in
#golang
? One way to do this is the UnmarshalJSON method, which implements the json.Unmarshaler interface ()
What is even neater - you can still leverage the json package to do the heavy lifting for you.
Did you know that
#golang
supports receive-only and send-only channels? These are useful when defining a func that only needs to perform one type of operation as it can prevent developers mistakes.
Exercise 7 which demonstrates how to build a CLI task manager in Go is now live - 💥💥💥
#golang
screencast videos are about 1hr 30m in total and cover:
- Building a CLI with spf13/cobra
- Working with BoltDB
- Using "go install"
I built a thing →
I'm trying to create tools to make debugging common errors in
#golang
easier. Errors in Go is my first attempt at a "database" of common errors and fixes. PRs and issues w/ suggested errors are encouraged!
I spent 6 hours trying to get something working only to lay down for bed and immediately think of a solution. Some days you just need to step away for a bit.
If you use
#golang
's standard library for your http servers (pretty much all third party libs also do this), all incoming web requests will already be running in a goroutine before they touch your handlers.
Historically I have limited my blog () to mostly
#golang
articles, but I do a lot more than write Go code. Would anyone be interested in me writing other aspects of my life? Eg I could write about working
#remote
in a small town.
I've been using databases for quite some time, but I feel like
@rakyll
's experience makes me look like a toddler who has been playing with blocks while she has been building spaceships 😂 Should be a good episode. I hope to learn a lot! 😁
Today at 3pm ET we will be recording an episode about
#databases
! Tune in to hear
@rakyll
educate other panelists (
@matryer
and
@joncalhoun
) on the downsides to AUTOINCREMENTing, how to successfully perform live migrations, and more.
#golang
(
#golang
programming exercises) is nearing 20k signups, and I am oh so close to 2k followers on Twitter. I need to do something to celebrate. Maybe a free mini-course? Or in the near term, perhaps a sale on my premium courses? Ideas?
Getting started in tech is 100x easier with a fun project. What was the first thing that sucked you into programming and made it fun?
How about
#golang
- what was the first thing you worked on that made it hard to walk away from the computer?
You can learn to paint in a few minutes, but becoming an artist takes a lifetime.
Becoming a programmer is similar. You can learn to code hello world in an hour, but you can also spend the rest of your life learning and improving.
Let's try to visualize a nil pointer error in
#golang
.
When we declare a variable that is NOT a pointer, it is similar to printing out an empty form so that we can fill it out.
For the next few weeks my
#golang
courses will be discounted.
In addition to the discount, I am going to do everything I can to help out anyone who can't afford a course.
Read more →
(1/4)
Need to sort a custom data type in
#golang
? Just implement sort.Interface () with a new type for each sort criteria. This means you can have multiple sorts for the same type.
Runnable example 👉
I'm looking for examples of
#generics
being used in
#golang
code. Ideally I'd like to see:
1. What you did before generics.
2. What you are doing with generics.
In both cases a go playground example would be ideal. I want specific, runnable & easy to share examples.
I really like the
#golang
error changes made in 1.13, but it does make switch statements over errors a little more verbose. I'm not sure if this is a bad thing, but I don't LOVE declaring all those variables before a switch. I wonder if this could be improved... 🤔
I bet you didn't realize it was this easy to create a static site generator with
#golang
!
Probably not ready for a public audience, but it is a nice way to hack together a single static HTML landing page.
Do you know any lesser-known people writing, teaching, or otherwise helping educate Gophers? Let me know who they are and share some examples of their work - I'd love to help out where I can! 😁
#golang
I wonder if a mini-course demonstrating my dev environment and other tips/tricks I use to speed things up when doing
#golang
#dev
would be helpful... 🤔
@spf13
Feeling able to say "I don't understand" is like a superpower, and great teams are eager to teach something new rather than shame me for not knowing. I now can't imagine working with people who shamed me for not knowing something.
Today is my 7th anniversary with my amazing, wonder, beautiful, and supportive wife. Words can't describe how happy I am to have someone who stands by me and I honestly don't believe I would be doing what I do today if it weren't for her motivating me.
Never build your own
#sql
queries. See the code attached for an example of this going poorly.
Use existing, well tested libs to avoid this. Some
#golang
options:
database/sql - in the standard lib
Need the ability to log in your
#golang
code, but don't want to pass in a logger all the time? Try limiting to just a single logging function and create a reusable type that gives it a sane default value, then embed that type.
In many cases, context values can be avoided altogether and the resulting code's dependencies will be much clearer. Two ways to do this are struct fields and closures.
#golang
#context
This is important b/c context values should be context-specific. See
My wife drinks decaf coffee. I drink regular. This morning I have been dragging. She has been feeling super anxious. Turns out we swapped coffees on accident 🤦♂️
I use the empty struct all the time to create sets using Go's map type. What are some other use cases for the empty struct?
#golang
More on the empty struct -