{"id":152392,"date":"2021-06-11T14:18:41","date_gmt":"2021-06-11T13:18:41","guid":{"rendered":"https:\/\/blog.jetbrains.com\/?post_type=go&#038;p=152392"},"modified":"2021-06-11T14:18:43","modified_gmt":"2021-06-11T13:18:43","slug":"how-to-increment-the-major-version-of-a-go-module-using-goland","status":"publish","type":"go","link":"https:\/\/blog.jetbrains.com\/en\/go\/2021\/06\/11\/how-to-increment-the-major-version-of-a-go-module-using-goland","title":{"rendered":"How to increment the major version of a go module using GoLand"},"content":{"rendered":"\n<p>Let&#8217;s look at the workflow of incrementing the major version of a module using the module definition taken from our <a href=\"https:\/\/github.com\/JetBrains\/whatsnewingoland\/blob\/main\/2021.1\/14%20-%20rename%20go%20modules\/go.mod\" target=\"_blank\" rel=\"noopener\">What&#8217;s New in GoLand repository<\/a>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">module renameab.le\/module\n\ngo 1.11<\/pre>\n\n\n\n<p>Upgrading a module means bumping the version tag in version control. We also need to change our <strong>import paths<\/strong>. For example, if to bump the module version from `v1` to `v2`, we need our imports changed from:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&quot;renameab.le\/module\/pkg\/log&quot;<\/pre>\n\n\n\n<p>to<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&quot;renameab.le\/module\/v2\/pkg\/log&quot;<\/pre>\n\n\n\n<p>Obviously, this can appear in lots of places in the code. Good news: the IDE can do this for you.<\/p>\n\n\n\n<p>With the 2021.1 version of GoLand, you can use the <em>Rename<\/em> refactoring to complete this workflow. To do this, place the cursor on the module&#8217;s name in the <em>go.mod<\/em> file, in our example <em>renameab.le\/module<\/em>, and invoke the <em>Rename<\/em> refactoring via <em>Shift+F6<\/em>. (You can also invoke the <em>Rename<\/em> refactoring using the <em>Refactor This<\/em> feature via <em>Ctrl+Alt+Shift+T<\/em> on Windows\/Linux or <em>Ctrl+T <\/em>on macOS.)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/06\/increase-a-go-module-major-version.png\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/06\/increase-a-go-module-major-version.gif\"\/><\/figure>\n\n\n\n<p><strong>Pro tip:<\/strong> This will also update all references to the current module name across all the Go files, test or not. Click on the <em>Preview<\/em> button to see where the change will take place.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/06\/preview-renaming-a-module.png\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/06\/preview-renaming-a-module.gif\"\/><\/figure>\n\n\n\n<p>Sometimes, as soon as you click <em>Refactor<\/em>, you change your mind. &#8220;Oh no, now I have to find all those imports, file name changes, etc., and put them back.&#8221; Good news: the IDE can undo that entire editor transaction, including file changes and VCS operations.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/06\/undo-go-module-rename-1.png\" data-gif-src=\"https:\/\/blog.jetbrains.com\/wp-content\/uploads\/2021\/06\/undo-go-module-rename-1.gif\"\/><\/figure>\n\n\n\n<p>Another reason to use this operation: as with any IDE refactoring, <a href=\"https:\/\/blog.jetbrains.com\/en\/go\/2019\/10\/10\/top-25-editing-features-of-goland-ide-part-3#local-history\">the Local History<\/a> can save you. Here&#8217;s how the <em>Rename<\/em> operation looks like in the <em>Local History<\/em>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/3_QixmRt1nTkXbsW05VO6RhnkB63xYC87jvGi3ddbs4O5XC3zC3vBKGdEeqViqlG6pBA2dB-szY1b4q80Bf26aZzjuvWEGQ3tef_gQ2A9IuuMdnoVV0fqS-JhkovJqCSIUtlr8A-\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>Our IDEs are great at automating routine work. Here we saw how we could use the <em>Rename<\/em> refactoring to make sure that we can safely and efficiently rename our modules when incrementing their major version. The <a href=\"https:\/\/blog.jetbrains.com\/en\/go\/2018\/12\/07\/refactorings-in-goland-rename-refactoring\">Rename refactoring<\/a> can also change the name of identifiers, files, and folders. GoLand contains other refactoring features too, and you can find out more about them in this <a href=\"https:\/\/blog.jetbrains.com\/go\/tag\/refactorings\/\">series of articles<\/a>.<br><br>Please let us know your feedback in the comments section below, on <a href=\"https:\/\/youtrack.jetbrains.com\/issues\/Go\" target=\"_blank\" rel=\"noopener\">our issue tracker<\/a>, in <a href=\"https:\/\/app.slack.com\/client\/T029RQSE6\/C3FJ8M2PN\/\" target=\"_blank\" rel=\"noopener\">the #goland channel of Gophers Slack<\/a>, or via our social media such as <a href=\"https:\/\/twitter.com\/GoLandIDE\" target=\"_blank\" rel=\"noopener\">Twitter @GoLandIDE<\/a>.<\/p>\n","protected":false},"author":828,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","categories":[2347],"tags":[3919,91,659],"cross-post-tag":[],"acf":[],"_links":{"self":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/go\/152392"}],"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=152392"}],"version-history":[{"count":10,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/go\/152392\/revisions"}],"predecessor-version":[{"id":153501,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/go\/152392\/revisions\/153501"}],"wp:attachment":[{"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/media?parent=152392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/categories?post=152392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/tags?post=152392"},{"taxonomy":"cross-post-tag","embeddable":true,"href":"https:\/\/blog.jetbrains.com\/en\/wp-json\/wp\/v2\/cross-post-tag?post=152392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}