<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aarush Goyal</title>
    <description>The latest articles on DEV Community by Aarush Goyal (@aarushgoyal).</description>
    <link>https://dev.to/aarushgoyal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F485744%2F5aa15ee1-e899-468f-bf9c-92225dce29ff.png</url>
      <title>DEV Community: Aarush Goyal</title>
      <link>https://dev.to/aarushgoyal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aarushgoyal"/>
    <language>en</language>
    <item>
      <title>Git Hooks for your Golang project</title>
      <dc:creator>Aarush Goyal</dc:creator>
      <pubDate>Mon, 07 Mar 2022 05:42:32 +0000</pubDate>
      <link>https://dev.to/aarushgoyal/git-hooks-for-your-golang-project-1168</link>
      <guid>https://dev.to/aarushgoyal/git-hooks-for-your-golang-project-1168</guid>
      <description>&lt;p&gt;I have been developing in JavaScript for a while now and one of my favourite tool was &lt;a href="https://www.npmjs.com/package/husky" rel="noopener noreferrer"&gt;husky&lt;/a&gt; but when I started developing on golang I really missed the husky tool to manage my git hooks so I created a spin off to husky written in golang. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/automation-co/husky" rel="noopener noreferrer"&gt;Check it out&lt;br&gt;
&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lets see how you can use it?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5r3e74u5ntjz0i1y6kiu.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5r3e74u5ntjz0i1y6kiu.gif" alt="Captain Hook"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go &lt;span class="nb"&gt;install &lt;/span&gt;github.com/automation-co/husky@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Getting Started
&lt;/h3&gt;

&lt;p&gt;You can initialise husky by &lt;code&gt;$ husky init&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Make sure you have git initialised&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will make the .husky folder with the hooks folder and a sample pre-commit hook&lt;/p&gt;

&lt;p&gt;You can add hooks using&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;husky add &amp;lt;hook&amp;gt; &lt;span class="s2"&gt;"
  &amp;lt;your commands for that hook&amp;gt;
"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;husky add pre-commit &lt;span class="s2"&gt;"
  go build -v ./... 
  go test -v ./...
"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have made any other changes in the hooks you can appply them by using &lt;code&gt;$ husky install&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Familiar with Git Hooks
&lt;/h2&gt;

&lt;p&gt;Learn more about git hooks from these useful resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks" rel="noopener noreferrer"&gt;https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.atlassian.com/git/tutorials/git-hooks" rel="noopener noreferrer"&gt;https://www.atlassian.com/git/tutorials/git-hooks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://medium.com/@f3igao/get-started-with-git-hooks-5a489725c639" rel="noopener noreferrer"&gt;https://medium.com/@f3igao/get-started-with-git-hooks-5a489725c639&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Other Alternatives
&lt;/h3&gt;

&lt;p&gt;If you feel husky does not fulfill your needs you can also check out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/typicode/husky" rel="noopener noreferrer"&gt;https://github.com/typicode/husky&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pre-commit.com/" rel="noopener noreferrer"&gt;https://pre-commit.com/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>go</category>
      <category>git</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>Get Started with Go!</title>
      <dc:creator>Aarush Goyal</dc:creator>
      <pubDate>Sun, 30 May 2021 17:57:56 +0000</pubDate>
      <link>https://dev.to/aarushgoyal/get-started-with-go-1d1m</link>
      <guid>https://dev.to/aarushgoyal/get-started-with-go-1d1m</guid>
      <description>&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;I use an Arch based Linux distribution so I am going to install golang through &lt;code&gt;pacman&lt;/code&gt;. If you are a Mac or a Windows user you can see the installation procedure over &lt;a href="https://golang.org/dl/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updated the packages&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pacman &lt;span class="nt"&gt;-Syu&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install golang&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;pacman &lt;span class="nt"&gt;-Sy&lt;/span&gt; go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Testing if the installation was successful&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;go version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it should give us an output like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go version go&amp;lt;version number&amp;gt; linux/amd64
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting Up the Code Editor
&lt;/h2&gt;

&lt;p&gt;Make a directory and run &lt;code&gt;go mod init github.com/&amp;lt;github username&amp;gt;/&amp;lt;repo name&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will create  a &lt;code&gt;go.mod&lt;/code&gt; file in the working directory.&lt;/p&gt;

&lt;p&gt;If you are a JS developer you will be familiar to the &lt;code&gt;npm init&lt;/code&gt; command that creates a &lt;code&gt;package.json&lt;/code&gt; in the working directory to store the information about all the dependencies that the npm package would use. &lt;code&gt;go mod init&lt;/code&gt; is similar to that and works in a similar way.&lt;/p&gt;

&lt;p&gt;Open the working directory in Visual Code by running the command &lt;code&gt;code .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Download Go extension from the &lt;a href="https://code.visualstudio.com/docs/languages/go" rel="noopener noreferrer"&gt;Visual Studio Code Marketplace&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see a pop up notification in Visual Studio Code like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz574uwv4rezih4z3k8fs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz574uwv4rezih4z3k8fs.png" alt="Get%20Started%20with%20Go!%20067d2ddd6ff240edaba2b303ef59c705/Untitled.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;code&gt;Install all&lt;/code&gt; and wait some time.&lt;/p&gt;

&lt;p&gt;After the process are completed we can now get to writing your first few lines in go.&lt;/p&gt;

&lt;p&gt;For a video tutorial till now you can check this &lt;a href="https://youtu.be/1MXIGYrMk80" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hello World
&lt;/h2&gt;

&lt;p&gt;Hello world is pretty much the first line of code that most programmers write while learning a new language so how can we miss this tradition.&lt;/p&gt;

&lt;p&gt;Make a new file called &lt;code&gt;main.go&lt;/code&gt; and write the following lines of code :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapx6f29x7ibau69ccxs4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapx6f29x7ibau69ccxs4.gif" alt="https://media.giphy.com/media/13HgwGsXF0aiGY/giphy.gif"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="s"&gt;"fmt"&lt;/span&gt;

&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello world"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets take a look at what we have written. &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;package main&lt;/code&gt; tells the Go compiler that the package should compile as an executable program instead of a shared library.&lt;/p&gt;

&lt;p&gt;The main function in the &lt;code&gt;package main&lt;/code&gt; will be the entry point of our executable program. When you build shared libraries, you will not have any main package and main function in the package.&lt;/p&gt;

&lt;p&gt;We can import modules using the &lt;code&gt;import&lt;/code&gt; command like in the Hello World program we just wrote we imported the &lt;code&gt;fmt&lt;/code&gt; library.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fmt&lt;/code&gt; library is very similar to the &lt;code&gt;print&lt;/code&gt; commands in python or &lt;code&gt;console.log&lt;/code&gt; in java-script.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;fmt.Println()&lt;/code&gt; displays the data inside it in the terminal.&lt;/p&gt;

&lt;p&gt;To get more information about &lt;code&gt;fmt&lt;/code&gt;module click &lt;a href="http://golang.org/pkg/fmt/#hdr-Printing" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Executing our code
&lt;/h2&gt;

&lt;p&gt;To run our code we can use &lt;code&gt;go run main.go&lt;/code&gt; command in the terminal.&lt;/p&gt;

&lt;p&gt;We can also compile the go code into a executable binary file by using &lt;code&gt;go build main.go&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can then execute the file by &lt;code&gt;./main&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;go run main.go
Hello world

&lt;span class="nv"&gt;$ &lt;/span&gt;go build main.go

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls
&lt;/span&gt;go.mod main.go main

&lt;span class="nv"&gt;$ &lt;/span&gt;./main
Hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You are all set for learning Go!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/8YHmc8luwmJJjFY7zh/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/8YHmc8luwmJJjFY7zh/giphy.gif" alt="https://media.giphy.com/media/8YHmc8luwmJJjFY7zh/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>programming</category>
      <category>vscode</category>
    </item>
  </channel>
</rss>
