Migrating from Dep to Go Modules
Dep, a dependency management tool for Go, is now obsolete with the introduction of Go modules. Migrating from Dep to Go modules is straightforward.
Steps to Migrate
-
Ensure Compatibility: Ensure Go version 1.11 or later is used by running go version.
-
Move or Set Environment Variable: Move the code outside of GOPATH or set export GO111MODULE=on.
-
Initialize Module: Run go mod init [module path] to import dependencies from Gopkg.lock.
-
Clean Up: Use go mod tidy to remove redundant and add missing dependencies.
-
Consider Deleting Vendor Folder (Optional): Remove the vendor folder or move it to the trash.
-
Test Build: Perform a test build using go build to verify functionality.
-
Delete Obsolete Files: Delete Gopkg.lock and Gopkg.toml as they are no longer needed.
Importing Dependencies
Go reads the Gopkg.lock file and automatically imports the dependencies into the go.mod file.
Maintaining Vendor Folder (Optional)
If preferred, follow these additional steps:
-
Copy Dependencies: Run go mod vendor to copy dependencies into the vendor folder.
-
Utilize Vendor Folder: Run go build -mod=vendor to ensure the build process uses the vendor folder.
The above is the detailed content of How to Migrate from Dep to Go Modules?. For more information, please follow other related articles on the PHP Chinese website!