{"id":2277,"date":"2022-07-07T14:21:46","date_gmt":"2022-07-07T14:21:46","guid":{"rendered":"https:\/\/blog.samarthya.me\/wps\/?p=2277"},"modified":"2022-07-07T14:54:36","modified_gmt":"2022-07-07T14:54:36","slug":"go-modules","status":"publish","type":"post","link":"https:\/\/blog.samarthya.me\/wps\/2022\/07\/07\/go-modules\/","title":{"rendered":"Go Modules"},"content":{"rendered":"\n<p>If you are like me and getting errors while trying to compile your go lang code without having a <code>go.mod<\/code> in <code>v1.18<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package src is not in GOROOT (\/usr\/local\/Cellar\/go\/1.18.3\/libexec\/src\/src)<\/code><\/pre>\n\n\n\n<p>Remember you have overlooked a basic change that happened post <code>1.16<\/code><\/p>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-alert smb-alert wp-block-snow-monkey-blocks-alert-is-layout-constrained\"><div class=\"smb-alert__title\"><i class=\"fa-solid fa-exclamation-circle\"><\/i><strong>Module Aware Mode<\/strong><\/div><div class=\"smb-alert__body is-layout-constrained wp-block-alert-is-layout-constrained\"><p>The&nbsp;<code>go<\/code>&nbsp;command now builds packages in module-aware mode by default, even when no&nbsp;<code>go.mod<\/code>&nbsp;is present.&nbsp;<\/p><\/div><\/div>\n\n\n\n<figure class=\"wp-block-pullquote has-border-color has-black-border-color has-light-green-cyan-background-color has-background\" style=\"border-radius:39px;border-width:1px;font-style:normal;font-weight:500\"><blockquote><p><a href=\"https:\/\/go.dev\/blog\/go116-module-changes\" data-type=\"URL\" data-id=\"https:\/\/go.dev\/blog\/go116-module-changes\">Helpful Link<\/a><\/p><cite>https:\/\/go.dev\/blog\/go116-module-changes<\/cite><\/blockquote><\/figure>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-background-color has-background\"><code>&gt; go env|grep GO111\nGO111MODULE=\"\"<\/code><\/pre>\n\n\n\n<p>Set it off<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-background-color has-background\"><code>go env -w GO111MODULE=off<\/code><\/pre>\n\n\n\n<p>Try again<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>go test\nPASS\nok      _\/Users\/samarthya\/sourcebox\/github.com\/git.golang\/project-one\/src        0.099s<\/code><\/pre>\n\n\n\n<div class=\"wp-block-snow-monkey-blocks-balloon smb-balloon wp-block-snow-monkey-blocks-balloon-is-layout-constrained\"><div class=\"smb-balloon__person\"><div class=\"smb-balloon__figure\"><img decoding=\"async\" width=\"129\" height=\"150\" src=\"https:\/\/blog.samarthya.me\/wps\/wp-content\/uploads\/2022\/07\/Gomod.png\" alt=\"\" class=\"wp-image-2278\"\/><\/div><div class=\"smb-balloon__name\"><\/div><\/div><div class=\"smb-balloon__body is-layout-constrained wp-block-balloon-is-layout-constrained\"><p>You can also set&nbsp;<code>GO111MODULE<\/code>&nbsp;to&nbsp;<code><strong>auto<\/strong><\/code>&nbsp;to enable module-aware mode only when a go.mod file is present in the current directory or any parent directory.<\/p><p><strong><code>go env -w GO111MODULE=auto<\/code><\/strong><\/p><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you are like me and getting errors while trying to compile your go lang code without having a go.mod in v1.18 Remember you have overlooked a basic change that happened post 1.16 Module Aware Mode The&nbsp;go&nbsp;command now builds packages in module-aware mode by default, even when no&nbsp;go.mod&nbsp;is present.&nbsp; Helpful Link https:\/\/go.dev\/blog\/go116-module-changes Set it off [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2278,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"image","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[137,34],"tags":[],"class_list":["post-2277","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-golang","category-technical","post_format-post-format-image"],"_links":{"self":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/comments?post=2277"}],"version-history":[{"count":3,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2277\/revisions"}],"predecessor-version":[{"id":2282,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/posts\/2277\/revisions\/2282"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media\/2278"}],"wp:attachment":[{"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/media?parent=2277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/categories?post=2277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.samarthya.me\/wps\/wp-json\/wp\/v2\/tags?post=2277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}