GO TECHNIQUE
Golang Technique: How to Add Default Values to Function Parameters?
Are you one of the many coders who find it annoying that Go doesn’t have default parameter values? If that’s the case, you’re far from being the only one.
Ever wish that Go had default parameter values built in?
I know I have.
You end up writing extra lines just to see if a value is given and then set a default yourself if it’s not.
It’s not a big issue, but it does make coding a bit more work than it needs to be. The upside is there are ways to deal with this that are okay. They’re not as clean as built-in options, but they do the job well enough.
By the way, you might also want to check out my post on custom struct tags in Go. Another small way to make your Go coding a touch easier. We should take whatever small improvements we can to make Go coding more straightforward, right?