Home  >  Article  >  Backend Development  >  How to Migrate from Dep to Go Modules?

How to Migrate from Dep to Go Modules?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-13 08:30:02181browse

How to Migrate from Dep to Go Modules?

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

  1. Ensure Compatibility: Ensure Go version 1.11 or later is used by running go version.
  2. Move or Set Environment Variable: Move the code outside of GOPATH or set export GO111MODULE=on.
  3. Initialize Module: Run go mod init [module path] to import dependencies from Gopkg.lock.
  4. Clean Up: Use go mod tidy to remove redundant and add missing dependencies.
  5. Consider Deleting Vendor Folder (Optional): Remove the vendor folder or move it to the trash.
  6. Test Build: Perform a test build using go build to verify functionality.
  7. 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:

  1. Copy Dependencies: Run go mod vendor to copy dependencies into the vendor folder.
  2. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn