<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Brian Wieder's Blog]]></title><description><![CDATA[Brian Wieder's Blog]]></description><link>https://blog.bwieder.com</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 04:48:06 GMT</lastBuildDate><atom:link href="https://blog.bwieder.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Basics of a Go Program]]></title><description><![CDATA[What is Go?
Go is a fast growing language, designed by Google Engineers to take advantage of the features of modern computers, such as multiple cores/threads, while maintains easy to learn and use syntax. Furthermore, in some use cases, Go has been r...]]></description><link>https://blog.bwieder.com/basics-of-a-go-program</link><guid isPermaLink="true">https://blog.bwieder.com/basics-of-a-go-program</guid><category><![CDATA[Go Language]]></category><category><![CDATA[Tutorial]]></category><dc:creator><![CDATA[Brian Wieder]]></dc:creator><pubDate>Fri, 01 Jan 2021 18:59:31 GMT</pubDate><content:encoded><![CDATA[<h1 id="what-is-go">What is Go?</h1>
<p>Go is a fast growing language, designed by Google Engineers to take advantage of the features of modern computers, such as multiple cores/threads, while maintains easy to learn and use syntax. Furthermore, in some use cases, Go has been reported to use less memory and CPU when compared to similar programs written in other languages.</p>
<p>Go is being utilized in major projects such as Docker, and Kubernetes, as well as at large companies such as Google, Uber, and Netflix to name a few.</p>
<h1 id="simple-go-example">Simple Go Example</h1>
<p>First, let’s take a look at a basic Go file to figure out the basics.</p>
<pre><code><span class="hljs-keyword">package</span> main

<span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>

<span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
   fmt.Println(<span class="hljs-string">"Hello, World!"</span>)
}
</code></pre><p>This is just a simple program that when compiled and run, will print “Hello, World!” to the command line.</p>
<p>The first line of code in any Go file must be the the package declaration.</p>
<pre><code><span class="hljs-keyword">package</span> main
</code></pre><p>This line states the package that this file belongs to. A package allows you to separate your code, usually depending on the context of what that file’s code does. All you need to know for the basics of Go though, is that the package must either be the name of the folder that the file is in, or main. If you name the package main, then it must be an executable. This means that it must contain a main function, code that gets run when the program starts. I will cover the main function a bit later in the article.</p>
<p>Next, on line 4, we have the packages that our code imports/uses.</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-string">"fmt"</span>
</code></pre><p>Go provides a standard library that contains several packages that we can use, so that we get functionality without having to write the code ourselves. In this case, we are importing the fmt package. The fmt package provides functionality for all things formatting input and output.</p>
<p>Next, we have the main function, which is the function that gets run when the program executes.</p>
<pre><code><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">main</span><span class="hljs-params">()</span></span> {
   ...
}
</code></pre><p>On line 6, we have the call to the fmt package’s function Println, which prints the text Hello, World! to the console.</p>
<pre><code><span class="hljs-selector-tag">fmt</span><span class="hljs-selector-class">.Println</span>(<span class="hljs-string">"Hello, World!"</span>)
</code></pre><h1 id="running-a-go-program">Running a Go Program</h1>
<p>Now that we have a Go file written, time to run it!</p>
<p>First, we are going to build our program. To do this, we are going to use the go build command. You will want to open a terminal or command prompt in the same directory as your Go file. Also, you will want to take note of the name of your go file.</p>
<p>To build my file, I am going to run this command in my terminal</p>
<pre><code>$ <span class="hljs-keyword">go</span> build -o hello-world BasicsOfGoProgram.<span class="hljs-keyword">go</span>
</code></pre><p>This command builds my Go file BasicsOfGoProgram.go into an executable called hello-world. In order to build your file, you can replace hello-world with whatever you want your executable to be named, as well as replace BasicsOfGoProgram.go to the name of your Go file.</p>
<p>Finally, to run my program, I will run this command in my terminal</p>
<pre><code>$ ./hello-world
</code></pre><p>And I will see the output</p>
<pre><code><span class="hljs-type">Hello</span>, <span class="hljs-type">World!</span>
</code></pre><p>In order to run your application, you can replace hello-world with whatever you named your executable when you ran go build.</p>
<p>This allows you to manually build and run your application, however, Go also provides a method of building and running your program in just one command to make development just a little bit easier for you. For example, if I run this command in my terminal, it will build and run my go file</p>
<pre><code>$ <span class="hljs-keyword">go</span> run  BasicsOfGoProgram.<span class="hljs-keyword">go</span>
</code></pre><p>And I will see the output again</p>
<pre><code><span class="hljs-type">Hello</span>, <span class="hljs-type">World!</span>
</code></pre><h1 id="wrapping-up">Wrapping Up</h1>
<p>That was a basic introduction to Go, and I hope that you might have learned something if you are new to Go. I plan on making more articles articles about Go and other languages in the future. If you have any suggestions on how to improve this article, or anything else, feel free to leave a comment down below.</p>
]]></content:encoded></item></channel></rss>