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

The Go 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 Kubernetes, OpenShift or Terraform for example.

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.

Install Go in Fedora


Fedora provides an easy way to install the Go programming language via the official repository.

$ sudo dnf install -y golang
$ go version
go version go1.12.7 linux/amd64

Now that Go is installed, let’s write a simple program, compile it and execute it.

First program in Go


Let’s write the traditional “Hello, World!” program in Go. First create a main.go file and type or copy the following.

package main import "fmt" func main() { fmt.Println("Hello, World!")
}

Running this program is quite simple.

$ go run main.go
Hello, World!

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.

Building an executable of the program is as simple as running it.

$ go build main.go
$ ./main
Hello, World!

Using Go modules


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 go.mod and go.sum used to explicitly define the version of the dependencies.

To show how to use modules, let’s add a dependency to the hello world program.

Before changing the code, the module needs to be initialized.

$ go mod init helloworld
go: creating new go.mod: module helloworld
$ ls
go.mod main main.go

Next modify the main.go file as follow.

package main import "github.com/fatih/color" func main () { color.Blue("Hello, World!")
}

In the modified main.go, instead of using the standard library “fmt” to print the “Hello, World!”. The application uses an external library which makes it easy to print text in color.

Let’s run this version of the application.

$ go run main.go
Hello, World!

Now that the application is depending on the github.com/fatih/color library, it needs to download all the dependencies before compiling it. The list of dependencies is then added to go.mod and the exact version and commit hash of these dependencies is recorded in go.sum.



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



Possibly Related Threads…
Thread Author Replies Views Last Post
  Fedora - Fedora Silverblue, an introduction for developers xSicKxBot 0 21 05-21-2020, 04:56 AM
Last Post: xSicKxBot
  Fedora - Using Fedora to implement REST API in JavaScript: part 2 xSicKxBot 0 28 05-19-2020, 12:23 AM
Last Post: xSicKxBot
  Fedora - The pieces of Fedora Silverblue xSicKxBot 0 31 05-16-2020, 02:08 AM
Last Post: xSicKxBot
  Fedora - How to manage network services with firewall-cmd xSicKxBot 0 34 05-12-2020, 02:01 AM
Last Post: xSicKxBot
  Fedora - How to rebase to Fedora 32 on Silverblue xSicKxBot 0 42 05-09-2020, 03:58 AM
Last Post: xSicKxBot
  Fedora - Fedora Classroom Session: IRC 101 xSicKxBot 0 40 05-08-2020, 02:41 AM
Last Post: xSicKxBot
  Fedora - 4 cool new projects to try in COPR for May 2020 xSicKxBot 0 44 05-05-2020, 04:42 AM
Last Post: xSicKxBot
  Fedora - Using mergerfs to increase your virtual storage xSicKxBot 0 49 05-02-2020, 02:37 AM
Last Post: xSicKxBot
  Fedora - What’s new in Fedora 32 Workstation xSicKxBot 0 44 05-01-2020, 04:42 AM
Last Post: xSicKxBot
  Fedora - Fedora 32 is officially here! xSicKxBot 0 58 04-29-2020, 11:44 PM
Last Post: xSicKxBot

Forum Jump:

[-]
Upcoming Events

[-]
Discord

[-]
Latest Threads
News - Poll: Box Art Brawl #45 – Phalanx
Last Post: xSicKxBot
Today 07:27 PM
» Replies: 0
» Views: 1
News - Pokemon Go Is Going Down For Main...
Last Post: xSicKxBot
Today 07:26 PM
» Replies: 0
» Views: 1
News - Nintendo’s Latest Patent Protects...
Last Post: xSicKxBot
Today 01:16 PM
» Replies: 0
» Views: 1
News - Fortnite Doomsday Event Start Dat...
Last Post: xSicKxBot
Today 01:16 PM
» Replies: 0
» Views: 1
[Tut] Python Join List [Ultimate Guide]
Last Post: xSicKxBot
Today 12:43 PM
» Replies: 0
» Views: 1
(Indie Deal) Tricky Traps Bundle, No Man...
Last Post: xSicKxBot
Today 12:43 PM
» Replies: 0
» Views: 1
News - New Amazon Listing Teases Second ...
Last Post: xSicKxBot
Today 06:56 AM
» Replies: 0
» Views: 3
News - Xenoblade Chronicles: Definitive ...
Last Post: xSicKxBot
Today 06:56 AM
» Replies: 0
» Views: 3
News - Minecraft Studio Gets Updated Nam...
Last Post: xSicKxBot
Today 06:56 AM
» Replies: 0
» Views: 3
News - Sony says after July 13th, new PS...
Last Post: xSicKxBot
Today 05:50 AM
» Replies: 0
» Views: 5

[-]
Twitter

[-]
Sponsored
Get the Deal of the Week at RefurBees.com

Copyright © SickGaming.net 2012-2019