For # 1.5, I would just add `t.Helper()` as the first line of `handleDBConnection`.
For # 3, this is also sometimes called the "Builder" pattern, and if any of the steps could cause an error, but you still want the simplicity of chaining, you can add a `Build` or `Do` method at the end of the chain that returns one or more values, including a (potentially "joined") error (typically accumulated during the building of the chain).
12 Personal Go Tricks That Transformed My Productivity
Nice list, I've learned a few things, thanks! One question: the link https://medium.com/@func25/go-performance-boosters-the-top-5-tips-and-tricks-you-need-to-know-e5cf6e5bc683 is behind paywall, do you have a copy somewhere else?
Very nice, thank you!
For # 1.5, I would just add `t.Helper()` as the first line of `handleDBConnection`.
For # 3, this is also sometimes called the "Builder" pattern, and if any of the steps could cause an error, but you still want the simplicity of chaining, you can add a `Build` or `Do` method at the end of the chain that returns one or more values, including a (potentially "joined") error (typically accumulated during the building of the chain).
I use this builder pattern here, for example: https://github.com/gmlewis/go-bjk/blob/master/examples/bifilar-electromagnet/main.go#L155
Because you have pointer as method receivers:
func (p *Person) AddAge() *Person {
p.Age++
return p
}
func (p *Person) Rename(name string) *Person {
p.Name = name
return p
}:
You can do:
func (p *Person) AddAge() {
p.Age++
}
func (p *Person) Rename(name string) {
p.Name = name
}
See:
https://go.dev/play/p/pSTTBms27ah