» VS Code debugging
Add the following to your user settings (or just the
configurations object inside the
.vscode/launch.json file in the root of your project) :
The debugging needs to be started from a file of the
main package, except when you debug a
» Upgrade all dependencies
» defer and log.Fatal/os.Exit
defer calls are not executed when
os.Exit() is called. So, it’s also not executed on the various
log.Fatal() calls, as those methods call
» io.Reader and errors
io.Reader interface is quite an exception in the Go ecosystem as it may return some succesfully read bytes together with an error. Thus, you can’t just handle the error as you would normally do, you may also have to check if bytes were read in the same call.
See the documentation https://pkg.go.dev/io#Reader
When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call.
As the name says, it’s an own main function for the tests. When you have several TestMain() functions in your project and import a package, the globals of the given package are not shared between the TestMain().
TestMain() needs to call
os.Exit(m.Run()) at the end of the function, otherwise it will always succeed.
» Versions > 1
When you create a new release (e.g. a git tag) with a version bump from 1 to 2, you have to adjust the
module in the
go.mod file and add a
Of course, also when there is any other major version bump >1. When you don’t do this, it will become a problem when importing your new package somewhere else.
» Make sure an interface is implemented
To make sure that your implementation satisfies a specific interface, you can add the following code:
When your implementation does not satisfy the interface, the compiler will complain.