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 - GNOME 3.34 released — coming soon in Fedora 31 xSicKxBot 0 44 09-13-2019, 08:19 PM
Last Post: xSicKxBot
  Fedora - How to set up a TFTP server on Fedora xSicKxBot 0 40 09-11-2019, 08:22 PM
Last Post: xSicKxBot
  Fedora - Firefox 69 available in Fedora xSicKxBot 0 42 09-11-2019, 02:19 PM
Last Post: xSicKxBot
  Fedora - Performing storage management tasks in Cockpit xSicKxBot 0 33 09-11-2019, 07:27 AM
Last Post: xSicKxBot
  Fedora - How to build Fedora container images xSicKxBot 0 31 09-10-2019, 11:14 PM
Last Post: xSicKxBot
  Fedora - How RPM packages are made: the spec file xSicKxBot 0 42 09-10-2019, 04:56 PM
Last Post: xSicKxBot
  Fedora - Command line quick tips: Using pipes to connect tools xSicKxBot 0 38 09-10-2019, 10:38 AM
Last Post: xSicKxBot
  Fedora - Using GNS3 with Fedora xSicKxBot 0 43 09-10-2019, 04:23 AM
Last Post: xSicKxBot
  Fedora - How RPM packages are made: the source RPM xSicKxBot 0 43 09-09-2019, 09:19 PM
Last Post: xSicKxBot
  Fedora - Managing credentials with KeePassXC xSicKxBot 0 31 09-09-2019, 03:06 PM
Last Post: xSicKxBot

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum software by © MyBB Copyright © SickGaming.net 2012-2019