SoFunction
Updated on 2025-03-01

Go project imports a solution to the problem of dependency red flag in GoLand

First check the introduced package name, followed by cache or network.

Initialize Go Modules

In your project directory, initialize Go Modules with the following command. This will create adocument:

go mod init <module_name>

For example, if your project ismyproject, can be initialized like this:

go mod init myproject

This will generate aFiles, similar to the following:

module myproject

go 1.20

Configure Go Modules in the IDE

Configure in GoLand:

  • OpenFile > Settings(orPreferenceson macOS).
  • Navigate toGo > Go Modules
  • Make sure it is enabledEnable Go Modules (vgo)Options.
  • examineGOPROXYSet it to ensure it is configured correctly:
GOPROXY=,direct

You can verify the module configuration of the current project using the following command:

go list -m all

This lists all modules and their versions in the project.

Clean up the cache

Cleaning up the cache includes cleaning up the mod cache and GoLand cache.

go clean -modcache

Make sure that GoLand has synced your module configuration:

  • In GoLand, right-click on the root of the project.
  • chooseSynchronize

Alternatively, rebuild the cache using the following steps:

  • OpenFile > Invalidate Caches / Restart
  • chooseInvalidate and Restart

Management dependencies

usego mod tidyClean up and update dependencies. This removes unused dependencies and ensures thatandThe file is latest:

go mod tidy

Sometimes dependencies may not be downloaded correctly, make sure you have downloaded all dependencies:

go mod download

Try manually updating and getting dependencies, especially those marked with red:

go get /cloudwego/[email protected]
go get /kitex-contrib/[email protected]

Check network proxy settings

Sometimes, network proxy settings can affect the downloads that depend on. Make sure your network settings allow access to the relevant Go module repository.

This is the article about the solution to the Go project's solution to the problem of importing dependency red in GoLand. For more related content on importing dependency red in GoGoLand, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!