go.sum<\/strong> file. <\/p>\n\n\n\nWe can also run this file now and it will give the correct output<\/p>\n\n\n\n
go run uuid.go<\/code><\/pre>\n\n\n\nOutput<\/strong><\/p>\n\n\n\ne594dc4d9a754bcb83b56e89b18b4b46<\/code><\/pre>\n\n\n\n<\/span>Example of indirect dependency in go.mod file<\/strong><\/span><\/h1>\n\n\n\nWe mentioned above that go.mod<\/strong> file might contain an indirect dependency in the below case.<\/p>\n\n\n\nAny indirect dependency which is not listed in the go.mod<\/strong> file of your direct dependency or if direct dependency doesn’t have a go.mod file , then that dependency will be added to the go.mod<\/strong> file with \/\/indirect <\/strong>as the suffix. We will see an example of this later in the article to know this better.<\/li><\/ul>\n\n\n\nLet’s understand it with an example. For that let’s first create a module again<\/p>\n\n\n\n
git mod init learn<\/code><\/pre>\n\n\n\nNow create a file learn.go<\/strong><\/p>\n\n\n\npackage main\n\nimport (\n\t\"github.com\/gocolly\/colly\"\n)\n\nfunc main() {\n\t_ = colly.NewCollector()\n}<\/code><\/pre>\n\n\n\nNotice that we have specified the dependency in the learn.go<\/strong> as<\/p>\n\n\n\ngithub.com\/gocolly\/colly<\/code><\/pre>\n\n\n\nSo github.com\/gocolly\/colly<\/strong> is a direct dependency of the learn module as it is directly imported in the module. Now let’s run the below command<\/p>\n\n\n\ngo mod tidy<\/code><\/pre>\n\n\n\nAfter running this command let’s now let’s again examine the contents of go.mod<\/strong> file. Since colly version v1.2.0 doesn’t have a go.mod file , all dependencies required by colly will be added to the go.mod<\/strong> file with \/\/indirect as suffix<\/p>\n\n\n\nDo a cat go.mod<\/strong><\/p>\n\n\n\nmodule learn\n\ngo 1.14\n\nrequire (\n\tgithub.com\/PuerkitoBio\/goquery v1.6.0 \/\/ indirect\n\tgithub.com\/antchfx\/htmlquery v1.2.3 \/\/ indirect\n\tgithub.com\/antchfx\/xmlquery v1.3.3 \/\/ indirect\n\tgithub.com\/gobwas\/glob v0.2.3 \/\/ indirect\n\tgithub.com\/gocolly\/colly v1.2.0\n\tgithub.com\/kennygrant\/sanitize v1.2.4 \/\/ indirect\n\tgithub.com\/saintfish\/chardet v0.0.0-20120816061221-3af4cd4741ca \/\/ indirect\n\tgithub.com\/temoto\/robotstxt v1.1.1 \/\/ indirect\n\tgolang.org\/x\/net v0.0.0-20201027133719-8eef5233e2a1 \/\/ indirect\n\tgoogle.golang.org\/appengine v1.6.7 \/\/ indirect\n)<\/code><\/pre>\n\n\n\nAll other dependencies are suffixed by \/\/indirect<\/strong>. Also checksum of all direct and indirect dependencies will be recorded in the go.sum file.<\/p>\n","protected":false},"excerpt":{"rendered":"Note: If you are interested in learning Golang, then for that we have a golang comprehensive tutorial series. Do check it out \u2013 Golang Comprehensive Tutorial Series. Now let’s see the current tutorial….<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[1],"tags":[3,4],"class_list":["post-4313","post","type-post","status-publish","format-standard","hentry","category-tech","tag-go","tag-golang"],"yoast_head":"\n
Understanding go.sum and go.mod file in Go (Golang) - Welcome To Golang By Example<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n