Migrating Effortlessly from Dep to Go Modules
If you're keen to transition from Dep to Go modules, here's a straightforward guide:
-
Ensure Go Version 1.11 or Later: Run go version to confirm compatibility.
-
Remove GOPATH or Enable Modules: Relocate your code outside of GOPATH or configure export GO111MODULE=on.
-
Initialize Module Path: Execute go mod init [module path] to fetch dependencies from Gopkg.lock.
-
Declutter and Optimize: Run go mod tidy to streamline imports and address indirect dependencies.
-
Consider Deleting Vendor Folder: This is optional, but you can enhance performance by removing the outdated directories rm -rf vendor/ or move to trash.
-
Test Build: Utilize go build to ensure successful migration.
-
Remove Obsolete Dep Files: Delete Gopkg.lock and Gopkg.toml to eliminate unnecessary remnants from Dep.
-
Vendor Folder Preservation (Optional): To retain your vendor folder, run go mod vendor to copy dependencies into it. Ensure to execute go build -mod=vendor to utilize your folder for building.
The above is the detailed content of How to Seamlessly Migrate from Dep to Go Modules?. For more information, please follow other related articles on the PHP Chinese website!