<?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: Nathan Ferreira</title>
    <description>The latest articles on DEV Community by Nathan Ferreira (@ntferr).</description>
    <link>https://dev.to/ntferr</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%2F457388%2Fa5f3e0a1-cd63-45b6-86fd-ae2c873f3864.jpg</url>
      <title>DEV Community: Nathan Ferreira</title>
      <link>https://dev.to/ntferr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ntferr"/>
    <language>en</language>
    <item>
      <title>Starting with Go</title>
      <dc:creator>Nathan Ferreira</dc:creator>
      <pubDate>Tue, 14 Mar 2023 19:49:30 +0000</pubDate>
      <link>https://dev.to/ntferr/starting-with-go-73a</link>
      <guid>https://dev.to/ntferr/starting-with-go-73a</guid>
      <description>&lt;h3&gt;
  
  
  Starting with Go
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;This is a brief tutorial.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Go is a statically typed, compiled high-level programming language and open source programming language created by Google.&lt;/p&gt;

&lt;p&gt;Golang was born out of a need to be more performative. Differs from other languages by being compiled, highly scalable and simplistic.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Features&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Syntactically similar to C, but with memory safety, garbage collection, structural typing, and CSP-style concurrency.&lt;/li&gt;
&lt;li&gt;Built-in facilities and library support for writing concurrent programs.&lt;/li&gt;
&lt;li&gt;Uses goroutines, a type of light-weight process, for concurrency.&lt;/li&gt;
&lt;li&gt;Uses channels for sending messages between goroutines and implementing concurrency control structures.&lt;/li&gt;
&lt;li&gt;Automatically standardized code formatting and style with gofmt tool.&lt;/li&gt;
&lt;li&gt;Rules enforced by Go encourage a particular explicit, concrete, and imperative programming style.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Use cases&lt;/strong&gt;:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Cloud &amp;amp; Network Services: With a strong ecosystem of tools and APIs on major cloud providers, it is easier than ever to build services with Go.&lt;/li&gt;
&lt;li&gt;Command-line Interfaces: With popular open source packages and a robust standard library, use Go to create fast and elegant CLIs.&lt;/li&gt;
&lt;li&gt;Web Development: With enhanced memory performance and support for several IDEs, Go powers fast and scalable web applications.&lt;/li&gt;
&lt;li&gt;DevOps &amp;amp; Site Reliability: With fast build times, lean syntax, an automatic formatter and doc generator, Go is built to support both DevOps and SRE.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Go has a memory model describing how goroutines must use channels or other operations to safely share data. The existence of channels sets Go apart from actor model-style concurrent languages like Erlang. Go does not provide any built-in notion of safe or verifiable concurrency, but idiomatic concurrent programs prefer channels.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Creators: Rob Pike and Ken Thompson&lt;/em&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Installing Go
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://go.dev/doc/install" rel="noopener noreferrer"&gt;Tutorial to install on windows&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Linux
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://asdf-vm.com/guide/getting-started.html" rel="noopener noreferrer"&gt;Tutorial to install asdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;execute the commands below:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;asdf plugin-add golang&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;asdf install golang&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;asdf global golang {{version of golang}}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;asdf shell golang {{version of golang}}&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Mac
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://brew.sh/" rel="noopener noreferrer"&gt;Tutorial to install Homebrew&lt;/a&gt;&lt;br&gt;
execute the command below:&lt;br&gt;
&lt;code&gt;brew install go&lt;/code&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  Primitive types
&lt;/h3&gt;

&lt;p&gt;We have &lt;strong&gt;string&lt;/strong&gt;, &lt;strong&gt;int&lt;/strong&gt;, &lt;strong&gt;uint&lt;/strong&gt;, &lt;strong&gt;bool, rune&lt;/strong&gt;, &lt;strong&gt;complex&lt;/strong&gt; and &lt;strong&gt;byte&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  1) Int
&lt;/h3&gt;

&lt;p&gt;Is one of the numeric types which represents a set of integers. There are various kind of integer types associated int. We have &lt;strong&gt;uint&lt;/strong&gt; or &lt;strong&gt;unsigned integers&lt;/strong&gt;, complex numbers, and int itself. Along with them are the different sets of numbers that they contain. For example, int8 contains all the 8-bit integers from -128 to +127, int16 contains all the 32-bit integers from -32768 to +32767.&lt;/p&gt;

&lt;p&gt;By default, when we write int, the bits associated with it depends on the architecture of your computer. It can be either 32 or 64 bits.&lt;/p&gt;
&lt;h3&gt;
  
  
  2) Uint — Unsigned Int
&lt;/h3&gt;

&lt;p&gt;Unsigned means no signal. That is means, there are no negative values only positives.&lt;/p&gt;
&lt;h3&gt;
  
  
  3) String
&lt;/h3&gt;

&lt;p&gt;This type represents a series of characters, used for names and some IDs. String type is usually used when we want to name things out or to write sentences.&lt;/p&gt;
&lt;h3&gt;
  
  
  4) Bool
&lt;/h3&gt;

&lt;p&gt;Bool is used to tell if it is true or false. In the world of programming is widely used to tell if the user is active, or if the validation of a function is true.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;uint8&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all unsigned 8-bit integers (0 to 255)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;uint16&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all unsigned 16-bit integers (0 to 65535)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;uint32&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all unsigned 32-bit integers (0 to 4294967295)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;uint64&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all unsigned 64-bit integers (0 to 18446744073709551615)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;int8&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all signed 8-bit integers (-128 to 127)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;int16&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all signed 16-bit integers (-32768 to 32767)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;int32&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all signed 32-bit integers (-2147483648 to 2147483647)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;int64&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all signed 64-bit integers (-9223372036854775808 to 9223372036854775807)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;float32&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all IEEE-754 32-bit floating-point numbers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;float64&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all IEEE-754 64-bit floating-point numbers&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;complex64&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all complex numbers with float32 real and imaginary parts&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;complex128&lt;/p&gt;

&lt;p&gt;&lt;em&gt;the set of all complex numbers with float64 real and imaginary parts&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;byte&lt;/p&gt;

&lt;p&gt;&lt;em&gt;alias for uint8 rune alias for int32&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Although &lt;strong&gt;&lt;em&gt;error&lt;/em&gt;&lt;/strong&gt; is a primitive type, it is an interface type, it is an interface type, which wrappers around the &lt;strong&gt;&lt;em&gt;string&lt;/em&gt;&lt;/strong&gt; type.&lt;/p&gt;


&lt;h3&gt;
  
  
  A simple Hello World
&lt;/h3&gt;

&lt;p&gt;Let’s start creating a folder named hello_world.&lt;/p&gt;

&lt;p&gt;Run the following command below so we can boot the Go configuration package.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go mod init hello_world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s write the code bellow&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;message&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s"&gt;"Hello World"&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="n"&gt;message&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;Execute the command below to execute the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;go run main.go
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.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%2Fqh0c9j8ypkkec6or7h7l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqh0c9j8ypkkec6or7h7l.png" alt=" " width="494" height="39"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>go</category>
      <category>beginners</category>
      <category>basic</category>
    </item>
  </channel>
</rss>
