Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fedora - Getting Started with Go on Fedora

#1
Getting Started with Go on Fedora

<div><p>The <a href="https://golang.org/">Go</a> programming language was first publicly announced in 2009, since then the language has become widely adopted. In particular Go has become a reference in the world of cloud infrastructure with big projects like <a href="https://kubernetes.io/">Kubernetes</a>, <a href="https://www.openshift.com/">OpenShift</a> or <a href="https://www.terraform.io/">Terraform</a> for example.</p>
<p> <span id="more-29183"></span> </p>
<p>Some of the main reasons for Go’s increasing popularity are the performances, the ease to write fast concurrent application, the simplicity of the language and fast compilation time. So let’s see how to get started with Go on Fedora.</p>
<h2>Install Go in Fedora</h2>
<p>Fedora provides an easy way to install the Go programming language via the official repository.</p>
<pre class="wp-block-preformatted">$ sudo dnf install -y golang
$ go version
go version go1.12.7 linux/amd64</pre>
<p>Now that Go is installed, let’s write a simple program, compile it and execute it.</p>
<h2>First program in Go</h2>
<p>Let’s write the traditional “Hello, World!” program in Go. First create a <em>main.go</em> file and type or copy the following.</p>
<pre class="wp-block-preformatted">package main import "fmt" func main() { fmt.Println("Hello, World!")
}</pre>
<p>Running this program is quite simple.</p>
<pre class="wp-block-preformatted">$ go run main.go
Hello, World!</pre>
<p>This will build a binary from main.go in a temporary directory, execute the binary, then delete the temporary directory. This command is really great to quickly run the program during development and it also highlights the speed of Go compilation.</p>
<p>Building an executable of the program is as simple as running it.</p>
<pre class="wp-block-preformatted">$ go build main.go
$ ./main
Hello, World!</pre>
<h2>Using Go modules</h2>
<p>Go 1.11 and 1.12 introduce preliminary support for modules. Modules are a solution to manage application dependencies. This solution is based on 2 files <em>go.mod</em> and <em>go.sum</em> used to explicitly define the version of the dependencies.</p>
<p>To show how to use modules, let’s add a dependency to the hello world program.</p>
<p>Before changing the code, the module needs to be initialized.</p>
<pre class="wp-block-preformatted">$ go mod init helloworld
go: creating new go.mod: module helloworld
$ ls
go.mod main main.go</pre>
<p>Next modify the main.go file as follow.</p>
<pre class="wp-block-preformatted">package main import "github.com/fatih/color" func main () { color.Blue("Hello, World!")
}</pre>
<p>In the modified main.go, instead of using the standard library “<em>fmt</em>” to print the “Hello, World!”. The application uses an external library which makes it easy to print text in color.</p>
<p>Let’s run this version of the application.</p>
<pre class="wp-block-preformatted">$ go run main.go
Hello, World! </pre>
<p>Now that the application is depending on the <em>github.com/fatih/color</em> library, it needs to download all the dependencies before compiling it. The list of dependencies is then added to <em>go.mod </em>and the exact version and commit hash of these dependencies is recorded in <em>go.sum</em>.</p></p>
</div>


https://www.sickgaming.net/blog/2019/08/...on-fedora/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Contribute to Fedora 39 Upgrade, Virtualization, and Cloud Test Day xSicKxBot 0 2,031 09-30-2023, 03:56 AM
Last Post: xSicKxBot
  Fedora - Share your game achievements with Gamerzilla xSicKxBot 0 1,002 09-27-2023, 09:59 AM
Last Post: xSicKxBot
  Fedora - Using Cockpit to graphically manage systems, without installing Cockpit on xSicKxBot 0 895 09-26-2023, 06:41 AM
Last Post: xSicKxBot
  Fedora - Announcing Fedora Linux 39 Beta xSicKxBot 0 917 09-20-2023, 09:48 AM
Last Post: xSicKxBot
  Fedora - Contribute at Passkey Auth, Fedora CoreOS and IoT Test Week xSicKxBot 0 890 09-19-2023, 12:23 PM
Last Post: xSicKxBot
  Fedora - Quick Fedora shirt update and sale of last stock with the old logo xSicKxBot 0 942 09-16-2023, 12:28 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Fedora Linux Test Week for Kernel 6.5 and Toolbx Test Day xSicKxBot 0 950 09-11-2023, 02:47 PM
Last Post: xSicKxBot
  Fedora - Fedora Linux Flatpak cool apps to try for September xSicKxBot 0 931 09-10-2023, 04:59 PM
Last Post: xSicKxBot
  Fedora - Contribute at the Test Week for the Anaconda WebUI Installer for Fedora Wor xSicKxBot 0 923 09-09-2023, 11:54 PM
Last Post: xSicKxBot
  Fedora - Docs workshop: Virtually writing together xSicKxBot 0 967 09-09-2023, 05:08 AM
Last Post: xSicKxBot

Forum Jump:


Users browsing this thread:
4 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016