{"id":441,"date":"2014-07-10T14:17:50","date_gmt":"2014-07-10T18:17:50","guid":{"rendered":"https:\/\/blog.splice.com\/?p=441"},"modified":"2024-01-18T14:54:03","modified_gmt":"2024-01-18T19:54:03","slug":"going-extra-mile-golint-go-vet","status":"publish","type":"post","link":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/","title":{"rendered":"Going the extra mile: golint and go vet"},"content":{"rendered":"<p><strong>Going the extra mile: golint and go vet<\/strong><\/p>\n<p>Go has a lot of awesome tools to help install packages and write readable, safe and correct code. Some are already well-known and widely used, such as <code>go get<\/code> or <code>gofmt<\/code>, but there are other gems hiding under the <code>go<\/code> command umbrella, or standing on their own in the <a href=\"https:\/\/code.google.com\/p\/go.tools\" target=\"_blank\" rel=\"noopener\">go.tools repository<\/a> or in the official <a href=\"https:\/\/github.com\/golang\" target=\"_blank\" rel=\"noopener\">github account<\/a>.<\/p>\n<p>Lately, we started running two complementary tools on our codebase: <em>golint<\/em>\u00a0and <em>go vet<\/em>.<\/p>\n<p><strong>Go with style<\/strong><\/p>\n<p>The linter cares about coding style. The README file <a href=\"https:\/\/github.com\/golang\/lint\" target=\"_blank\" rel=\"noopener\">in the repository<\/a>\u00a0says it best:<\/p>\n<blockquote>\n<p>Golint differs from gofmt. Gofmt reformats Go source code, whereas<br \/>golint prints out style mistakes.<\/p>\n<p>Golint differs from govet. Govet is concerned with correctness, whereas<br \/>golint is concerned with coding style. Golint is in use at Google, and it<br \/>seeks to match the accepted style of the open source Go project.<\/p>\n<\/blockquote>\n<p>So it will catch issues such as missing comments on exported symbols (or even badly formatted comments), variable naming that doesn&#8217;t follow the conventional Go style, useless specification of variable types when it can be inferred, etc. Most of its rules are based on <a href=\"https:\/\/code.google.com\/p\/go-wiki\/wiki\/CodeReviewComments\" target=\"_blank\" rel=\"noopener\">the style guide available in the Go wiki<\/a>.<\/p>\n<p><strong>Vetted code is better code<\/strong><\/p>\n<p>Unlike <code>golint<\/code>, <code>go vet<\/code>\u00a0can find actual errors in the code. From the command&#8217;s documentation:<\/p>\n<blockquote>\n<p>Vet examines Go source code and reports suspicious constructs, such as Printf<br \/>calls whose arguments do not align with the format string. Vet uses heuristics<br \/>that do not guarantee all reports are genuine problems, but it can find errors<br \/>not caught by the compilers.<\/p>\n<\/blockquote>\n<p><code>go vet<\/code>\u00a0starts where the compiler ends, and catches subtle issues that may easily pass through code review and unit testing. <code>Printf<\/code>-style errors are one of those, but for example it also reports position-based struct literals (non-keyed fields) when the struct belongs to an external package, since this creates a careless dependency on the internals of the package that exports the struct (order cannot be changed without breaking the outside code, let alone adding new fields).<\/p>\n<p><strong>Automating checks<\/strong><\/p>\n<p>We are still toying with different ways to run those checks automatically. One option is to configure it on a <code>pre-commit<\/code>\u00a0hook in the git repository. We list the messages returned by <code>golint<\/code>\u00a0as information only, because it can have plenty of false positives. <code>go vet<\/code>\u00a0can have false positives too, so it should not be a blocker to a commit, but both outputs can be very useful to have on a regular basis, and <em>git commit<\/em> can&#8217;t be avoided, so that&#8217;s an interesting place to run this.<\/p>\n<p>The important takeaway though is that those tools do exist, that they are complementary to the other tools you may already be using, and that they help write more readable and safer Go code.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"has-text-align-center\">Explore royalty-free sounds from leading artists, producers, and sound designers:<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button aligncenter\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/splice.com\/sounds\" target=\"_blank\" rel=\"noreferrer noopener\">Join Splice today<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Go has a lot of awesome tools to help install packages and write readable, safe and correct code. Some are already well-known and widely used, such as go get or gofmt, but there are other gems hiding under the go command umbrella&#8230;<\/p>\n","protected":false},"author":17,"featured_media":443,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[61],"tags":[115],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Going the extra mile: golint and go vet<\/title>\n<meta name=\"description\" content=\"Learn how to use golint and go vet to write better go code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Going the extra mile: golint and go vet\" \/>\n<meta property=\"og:description\" content=\"Learn how to use golint and go vet to write better go code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog | Splice\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Splice\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-10T18:17:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-18T19:54:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"332\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Martin Angers\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@splice\" \/>\n<meta name=\"twitter:site\" content=\"@splice\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Martin Angers\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\"},\"author\":{\"name\":\"Martin Angers\",\"@id\":\"https:\/\/splice.com\/blog\/#\/schema\/person\/5ed18aca22632875f5dc7a1729d7bc65\"},\"headline\":\"Going the extra mile: golint and go vet\",\"datePublished\":\"2014-07-10T18:17:50+00:00\",\"dateModified\":\"2024-01-18T19:54:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\"},\"wordCount\":458,\"publisher\":{\"@id\":\"https:\/\/splice.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg\",\"keywords\":[\"engineering\"],\"articleSection\":[\"Engineering\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\",\"url\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\",\"name\":\"Going the extra mile: golint and go vet\",\"isPartOf\":{\"@id\":\"https:\/\/splice.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg\",\"datePublished\":\"2014-07-10T18:17:50+00:00\",\"dateModified\":\"2024-01-18T19:54:03+00:00\",\"description\":\"Learn how to use golint and go vet to write better go code.\",\"breadcrumb\":{\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage\",\"url\":\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg\",\"contentUrl\":\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg\",\"width\":500,\"height\":332},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/splice.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Going the extra mile: golint and go vet\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/splice.com\/blog\/#website\",\"url\":\"https:\/\/splice.com\/blog\/\",\"name\":\"Splice Blog\",\"description\":\"An inside look at making music\",\"publisher\":{\"@id\":\"https:\/\/splice.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/splice.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/splice.com\/blog\/#organization\",\"name\":\"Splice\",\"alternateName\":\"Splice Sounds\",\"url\":\"https:\/\/splice.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/splice.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2023\/09\/Splice-logo-black-background.png\",\"contentUrl\":\"https:\/\/splice.com\/blog\/wp-content\/uploads\/2023\/09\/Splice-logo-black-background.png\",\"width\":2928,\"height\":1540,\"caption\":\"Splice\"},\"image\":{\"@id\":\"https:\/\/splice.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Splice\",\"https:\/\/x.com\/splice\",\"https:\/\/www.instagram.com\/splice\/\",\"https:\/\/www.youtube.com\/@splice\",\"https:\/\/discord.com\/invite\/splice\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/splice.com\/blog\/#\/schema\/person\/5ed18aca22632875f5dc7a1729d7bc65\",\"name\":\"Martin Angers\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/splice.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2895982ab79509e2de6cc2712dcdf99b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2895982ab79509e2de6cc2712dcdf99b?s=96&d=mm&r=g\",\"caption\":\"Martin Angers\"},\"url\":\"https:\/\/splice.com\/blog\/author\/martin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Going the extra mile: golint and go vet","description":"Learn how to use golint and go vet to write better go code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/","og_locale":"en_US","og_type":"article","og_title":"Going the extra mile: golint and go vet","og_description":"Learn how to use golint and go vet to write better go code.","og_url":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/","og_site_name":"Blog | Splice","article_publisher":"https:\/\/www.facebook.com\/Splice","article_published_time":"2014-07-10T18:17:50+00:00","article_modified_time":"2024-01-18T19:54:03+00:00","og_image":[{"width":500,"height":332,"url":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg","type":"image\/jpeg"}],"author":"Martin Angers","twitter_card":"summary_large_image","twitter_creator":"@splice","twitter_site":"@splice","twitter_misc":{"Written by":"Martin Angers","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#article","isPartOf":{"@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/"},"author":{"name":"Martin Angers","@id":"https:\/\/splice.com\/blog\/#\/schema\/person\/5ed18aca22632875f5dc7a1729d7bc65"},"headline":"Going the extra mile: golint and go vet","datePublished":"2014-07-10T18:17:50+00:00","dateModified":"2024-01-18T19:54:03+00:00","mainEntityOfPage":{"@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/"},"wordCount":458,"publisher":{"@id":"https:\/\/splice.com\/blog\/#organization"},"image":{"@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage"},"thumbnailUrl":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg","keywords":["engineering"],"articleSection":["Engineering"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/","url":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/","name":"Going the extra mile: golint and go vet","isPartOf":{"@id":"https:\/\/splice.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage"},"image":{"@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage"},"thumbnailUrl":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg","datePublished":"2014-07-10T18:17:50+00:00","dateModified":"2024-01-18T19:54:03+00:00","description":"Learn how to use golint and go vet to write better go code.","breadcrumb":{"@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#primaryimage","url":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg","contentUrl":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2014\/07\/linter.jpg","width":500,"height":332},{"@type":"BreadcrumbList","@id":"https:\/\/splice.com\/blog\/going-extra-mile-golint-go-vet\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/splice.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Going the extra mile: golint and go vet"}]},{"@type":"WebSite","@id":"https:\/\/splice.com\/blog\/#website","url":"https:\/\/splice.com\/blog\/","name":"Splice Blog","description":"An inside look at making music","publisher":{"@id":"https:\/\/splice.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/splice.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/splice.com\/blog\/#organization","name":"Splice","alternateName":"Splice Sounds","url":"https:\/\/splice.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/splice.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2023\/09\/Splice-logo-black-background.png","contentUrl":"https:\/\/splice.com\/blog\/wp-content\/uploads\/2023\/09\/Splice-logo-black-background.png","width":2928,"height":1540,"caption":"Splice"},"image":{"@id":"https:\/\/splice.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Splice","https:\/\/x.com\/splice","https:\/\/www.instagram.com\/splice\/","https:\/\/www.youtube.com\/@splice","https:\/\/discord.com\/invite\/splice"]},{"@type":"Person","@id":"https:\/\/splice.com\/blog\/#\/schema\/person\/5ed18aca22632875f5dc7a1729d7bc65","name":"Martin Angers","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/splice.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2895982ab79509e2de6cc2712dcdf99b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2895982ab79509e2de6cc2712dcdf99b?s=96&d=mm&r=g","caption":"Martin Angers"},"url":"https:\/\/splice.com\/blog\/author\/martin\/"}]}},"_links":{"self":[{"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/posts\/441"}],"collection":[{"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/comments?post=441"}],"version-history":[{"count":1,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/posts\/441\/revisions"}],"predecessor-version":[{"id":30429,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/posts\/441\/revisions\/30429"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/media\/443"}],"wp:attachment":[{"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/media?parent=441"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/categories?post=441"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/splice.com\/blog\/wp-json\/wp\/v2\/tags?post=441"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}