Go Modules Support Improvements in GoLand 2020.1
GoLand 2020.1 brings a lot of new features to Go Modules support, and today we’ll take a look at them and learn how to use them to maximize our productivity.
- Go Environment Variables
- Improved Vendoring support
- Completion in go.mod for require statements
- Completion in go.mod for replace statements
- Detect local paths in replace statements when committing
- Rename and Move refactoring aware replace statements
- Find Usages of a folder will show applicable replace statements
- Cleanup go.mod
Go Environment Variables
Until 2020.1, you could only configure the GOPROXY environment variable.
Starting with 2020.1, in addition to GOPROXY, you can also configure other variables like GOSUMDB, GOPRIVATE, GONOPROXY, and so on. If a variable is not on the list, you can choose the Other option from the list of variables and define your own.
There are two ways to configure these variables: by using the Environment field when you create a new Go Modules-based project, or with Settings/Preferences | Go | Go Modules for existing projects.
Note: The environment variables are also passed to the go build and your application and tests.
Improved Vendoring support
Go 1.14 has changed how vendoring works, and GoLand 2020.1 helps you keep up to date with the changes. Before Go 1.14, you had to enable the vendoring mode manually. Now it will automatically be enabled whenever a vendor folder exists.
Completion in go.mod for require statements
Completion for Go Modules’ import paths is now available in require statements. Only modules present in the Go Modules cache will be used. Versions currently have to be added manually.
Completion in go.mod for replace statements
Similar to the require statement, the replace statement also supports code completion. This works for both the name and the local path of the module.
Detect local paths in replace statements when committing
When using the replace statement to work on a dependency locally, it’s easy to commit that replacement to the repository, which can cause trouble later.
If you commit from the IDE, it will now run an inspection for replaced statements and warn you about it, so that you can always be sure that this problem won’t happen.
Note: Ensure that the Perform code analysis feature is enabled in the commit options to use this feature.
Rename and Move refactoring are aware replace statements
If the project needs to replace a module with a custom version, we can use the replace statement to point to that module. When times comes to perform maintenance, such as tidying up the locations, we can make use of the Rename and Move refactorings. Now, the IDE will automatically correct the locations of the modules in replace statements, so that everything is up to date and the code can work as before.
Find Usages of a folder will show applicable replace statements
In line with the rest of the improved support for the replace statement, it is possible to see whether a folder is being used as part of a replace statement. To use this feature, select a folder in the Project View tool window and invoke Find Usages via Alt+F7 on Windows/Linux or ⌥+F7 on macOS.
Over the course of a feature’s development cycle, it will be necessary to add imports, remove them, and so on. So, before we can commit the go.mod file, we can clean it up using the Sync dependencies of the <module> quick-fix.
That’s it for today. We’ve discussed how to effectively use the updated Go Modules support to code cleaner and faster using GoLand. Let us know your thoughts in the comment section below, on our issue tracker, or tweet us @GoLandIDE.
Subscribe to Blog updates
Thanks, we've got you!
How Do You Become More Productive with GoLand? Complete Interactive Courses!
GoLand has a lot of features, and it can be overwhelming at first. The trick is to remember the most important IDE actions and shortcuts, and the rest will follow. To help you, we have created the Learn GoLand section on the Welcome screen. It contains several interactive courses, mea…
Compile and run Go code using WSL 2 and GoLand
Today, I'm happy to introduce our latest feature to you to use Windows Subsystem for Linux version 2 (WSL 2, or simply WSL) to run or test Go applications seamlessly. This feature is called Run Targets and supports WSL 2, Docker, and SSH remotes. If you'd like to learn more about these, the overvi…
How to use Docker to compile and run Go code from GoLand
Up until now, when you wanted to test or run your shiny new code, you had only the local machine to do so. Many of our users have told us that they'd prefer to use Docker to run their code since that's where they will ultimately test, build, and deploy the code with their CI/CD pipeline. Today…
What Are Run Targets & How To Run Code Anywhere
Previously, when you were using GoLand, you could test and run your code only on the same machine you had the IDE installed on. You could use the FTP/SFTP Connectivity (ex. Remote Hosts Access) plugin and the Settings/Preferences | Tools | External Tools feature or the built-in Docker plugin to achi…