{"id":33503,"date":"2020-04-13T15:05:01","date_gmt":"2020-04-13T15:05:01","guid":{"rendered":"https:\/\/blog.jetbrains.com\/go\/?p=2243"},"modified":"2020-04-13T15:06:17","modified_gmt":"2020-04-13T15:06:17","slug":"go-modules-support-improvements-in-goland-2020-1","status":"publish","type":"go","link":"https:\/\/blog.jetbrains.com\/en\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1","title":{"rendered":"Go Modules Support Improvements in GoLand 2020.1"},"content":{"rendered":"<p>GoLand 2020.1 brings a lot of new features to Go Modules support, and today we&#8217;ll take a look at them and learn how to use them to maximize our productivity.<\/p>\n<p>We&#8217;ll cover:<\/p>\n<ul>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#go-environment-variables\">Go Environment Variables<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#improved-vendoring-support\">Improved Vendoring support<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#completion-in-gomod-for-require\">Completion in go.mod for require statements<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#completion-in-gomod-for-replace\">Completion in go.mod for replace statements<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#detect-local-paths\">Detect local paths in replace statements when committing<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#rename-and-move-refactoring\">Rename and Move refactoring aware replace statements<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#find-usages-of-a-folder\">Find Usages of a folder will show applicable replace statements<\/a><\/li>\n<li><a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/04\/13\/go-modules-support-improvements-in-goland-2020-1\/#cleanup-gomod\">Cleanup go.mod<\/a><\/li>\n<\/ul>\n<p>Before we continue, you might be interested in our series of blog posts on Go Modules support, which describes how to <a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/02\/26\/working-with-go-modules-getting-started\/\">get started<\/a>, <a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/03\/16\/working-with-go-modules-dependency-management\/\">manage dependencies<\/a>, <a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/03\/16\/working-with-go-modules-dependency-management\/#visualizing-the-dependencies-of-a-go-project\">visualize dependencies<\/a>, and <a href=\"https:\/\/blog.jetbrains.com\/go\/2020\/03\/25\/working-with-go-modules-versioning\/\">use versioning<\/a>.<\/p>\n<p><!--more--><\/p>\n<h2 id=\"go-environment-variables\">Go Environment Variables<\/h2>\n<p>Until 2020.1, you could only configure the <em>GOPROXY<\/em> environment variable.<\/p>\n<p>Starting with 2020.1, in addition to <em>GOPROXY<\/em>, you can also configure other variables like <em>GOSUMDB<\/em>, <em>GOPRIVATE<\/em>, <em>GONOPROXY<\/em>, 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.<\/p>\n<p>There are two ways to configure these variables: by using the <em>Environment<\/em> field when you create a new <em>Go Modules<\/em>-based project, or with <em>Settings\/Preferences | Go | Go Modules<\/em> for existing projects.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2244\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-01-Configure-Go-Environment-Variables-in-Go-Modules-optimized.png\" alt=\"Configure Go Environment Variables in Go Modules\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-01-Configure-Go-Environment-Variables-in-Go-Modules-optimized.gif\" \/><\/p>\n<p><strong>Note:<\/strong> The environment variables are also passed to the <em>go build<\/em> and your application and tests.<\/p>\n<h2 id=\"improved-vendoring-support\">Improved Vendoring support<\/h2>\n<p>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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2245\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-08-Vendoring-support-improvements-optimized.png\" alt=\"Vendoring support improvements\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-08-Vendoring-support-improvements-optimized.gif\" \/><\/p>\n<h2 id=\"completion-in-gomod-for-require\">Completion in go.mod for require statements<\/h2>\n<p>Completion for Go Modules&#8217; import paths is now available in <em>require<\/em> statements. Only modules present in the Go Modules cache will be used. Versions currently have to be added manually.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2246\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-02-Module-import-path-completion-in-require-directive-optimized.png\" alt=\"Module import path completion in require directive\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-02-Module-import-path-completion-in-require-directive-optimized.gif\" \/><\/p>\n<h2 id=\"completion-in-gomod-for-replace\">Completion in go.mod for replace statements<\/h2>\n<p>Similar to the <em>require<\/em> statement, the <em>replace<\/em> statement also supports code completion. This works for both the name and the local path of the module.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2247\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-03-Completion-in-require-directives-of-go.mod-files-optimized.png\" alt=\"Completion in require directives of go.mod files\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-03-Completion-in-require-directives-of-go.mod-files-optimized.gif\" \/><\/p>\n<h2 id=\"detect-local-paths\">Detect local paths in replace statements when committing<\/h2>\n<p>When using the <em>replace<\/em> statement to work on a dependency locally, it&#8217;s easy to commit that replacement to the repository, which can cause trouble later.<\/p>\n<p>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\u2019t happen.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2248\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-04-Detect-local-paths-in-replace-directives-when-committing-optimized.png\" alt=\"Detect local paths in replace directives when committing\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-04-Detect-local-paths-in-replace-directives-when-committing-optimized.gif\" \/><\/p>\n<p><strong>Note:<\/strong> Ensure that the Perform code analysis feature is enabled in the commit options to use this feature.<\/p>\n<h2 id=\"rename-and-move-refactoring\">Rename and Move refactoring are aware replace statements<\/h2>\n<p>If the project needs to replace a module with a custom version, we can use the <em>replace<\/em> statement to point to that module. When times comes to perform maintenance, such as tidying up the locations, we can make use of the <a href=\"https:\/\/blog.jetbrains.com\/go\/2018\/12\/07\/refactorings-in-goland-rename-refactoring\/\"><em>Rename<\/em><\/a> and <a href=\"https:\/\/blog.jetbrains.com\/go\/2018\/11\/30\/refactorings-in-goland-move-refactoring\/\"><em>Move<\/em><\/a> 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.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2249\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-05-Rename-and-Move-Refactoring-are-aware-replace-statements-optimized.png\" alt=\"Rename and Move Refactoring are aware replace statements\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-05-Rename-and-Move-Refactoring-are-aware-replace-statements-optimized.gif\" \/><\/p>\n<h2 id=\"find-usages-of-a-folder\">Find Usages of a folder will show applicable replace statements<\/h2>\n<p>In line with the rest of the improved support for the <em>replace<\/em> statement, it is possible to see whether a folder is being used as part of a <em>replace<\/em> statement. To use this feature, select a folder in the <em>Project View<\/em> tool window and invoke <em>Find Usages<\/em> via <em>Alt+F7<\/em> on <em>Windows\/Linux<\/em> or <em>\u2325+F7<\/em> on <em>macOS.<\/em><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2250\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-06-Find-Usages-of-folder-in-replace-statements-optimized.png\" alt=\"Find Usages of folder in replace statements\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-06-Find-Usages-of-folder-in-replace-statements-optimized.gif\" \/><\/p>\n<h2 id=\"cleanup-gomod\">Cleanup go.mod<\/h2>\n<p>Over the course of a feature\u2019s development cycle, it will be necessary to add imports, remove them, and so on. So, before we can commit the <em>go.mod<\/em> file, we can clean it up using the <em>Sync dependencies of the &lt;module&gt;<\/em> quick-fix.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"size-full wp-image-2251\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-07-Cleanup-go.mod-file-optimized.png\" alt=\"Cleanup go.mod file\" width=\"1500\" height=\"844\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2020\/04\/go-07-Cleanup-go.mod-file-optimized.gif\" \/><\/p>\n<p>That&#8217;s it for today. We\u2019ve 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 <a href=\"https:\/\/youtrack.jetbrains.com\/issues\/Go\" target=\"_blank\" rel=\"noopener\">our issue tracker<\/a>, or <a href=\"https:\/\/twitter.com\/GoLandIDE\" target=\"_blank\" rel=\"noopener\">tweet us @GoLandIDE<\/a>.<\/p>\n","protected":false},"author":828,"featured_media":0,"comment_status":"open","ping_status":"open","template":"","categories":[808],"tags":[782,3919,91],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/go\/33503"}],"collection":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/go"}],"about":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/types\/go"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/users\/828"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/comments?post=33503"}],"version-history":[{"count":0,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/go\/33503\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/media?parent=33503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/categories?post=33503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/tags?post=33503"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/cross-post-tag?post=33503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}