Your code is idiomatic and in my opinion it is the best practice available. Some would disagree for sure, but I would argue that this is the style seen all over the standard libraries in Golang. In other words, Go authors write error handling in this way.
More Related Contents:
- Create a generic channel
- How to pipe several commands in Go?
- How to use a module that is outside of “GOPATH” in another module?
- slice of struct != slice of interface it implements?
- How can I convert string to integer in golang
- How to dump goroutine stacktraces?
- Does Go compiler’s evaluation differ for constant expression and other expression
- Cyclic dependencies and interfaces
- Accessing struct fields inside a map value (without copying)
- Why do I get a “cannot assign” error when setting value to a struct as a value in a map? [duplicate]
- Can I concurrently write different slice elements
- Organize local code in packages using Go modules
- Golang defer behavior
- Stack vs heap allocation of structs in Go, and how they relate to garbage collection
- Is unnamed arguments a thing in Go?
- How to fix parsing go.mod module declares its path as “x” but was required as “y”
- What is the meaning of “dot parenthesis” syntax? [duplicate]
- What is the idiomatic Go equivalent of C’s ternary operator?
- Can I construct a slice of a generic type with different type parameters?
- How to import local packages in go?
- How to implement generic interfaces?
- How to compare Go errors
- How do you get the output of a system command in Go?
- How do you statically link a c library in go using cgo?
- Capture or assign golang template output to variable
- How to start a Go program as a daemon in Ubuntu?
- Call a Struct and its Method by name in Go?
- Big O of append in Golang
- Why do 2 time structs with the same date and time return false when compared with ==?
- Why a generic can’t be assigned to another even if their type arguments can?