Problem background:
During the development process of golang, sometimes the version of the library that it depends on is upgraded. If the specified library is updated automatically with go mod tidy, it will cause compilation problems or system operation problems. At this time, we can always import the specified version of the dependent library.
Example:
For example, during the development process, I called an unpackit library to decompress the compressed package. The specific function:
The v1.0.0 version of this function is that there is only one return value
func Unpack(reader io.Reader, destPath string) error
The latest version v0.1.0 of this library has only two return values error, and I used version 0.1.0 when developing
func Unpack(reader io.Reader, destPath string) (string, error)
If I simply go mod tidy, it will update the latest version to the latest version, resulting in compilation errors, I only need to use the specified version of the library
Solution:
Change go.mod, specify the required version of the library and add the version number after it
Then go mod tidy again, update to the specified version of the library, and recompile