Hello, Project Reclass

How to create your first hello world program in Go!

Why Go?

Go is a powerful language that powers the infrastructure that Project Reclass runs on. Docker, Kubernetes, Terraform, Vault, and even our chatbots are written in Go. Having even a basic understanding of the language can assist in making important infrastructure decisions, and interacting with the tools we utilize. Go also has a very large, friendly and diverse community.

Installation

First you'll need to install Golang, you can do so here. Go is often also found in most package managers so you can install it using the default manager for your system.

Follow the below instructions to properly finish setup on your Linux System

rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz
# Remove any previous versions of go and unzip the new version

export PATH=$PATH:/usr/local/go/bin
# Add Go to your $PATH

go version
# You should be able to run this from anyway and get the most recent version

Package managers may handle the path setting for you. Check this with echo $PATH

Writing the Code

Create a file named main.go and add the following:

// this is a comment

package main // You'll always need a package name this is usually main

import (
    "fmt" // "fmt" is the format package and contains the Println func
)

func main() { // You'll need a main function to run your code
    fmt.Println("Hello, Project Reclass") //Println prints to stdout and formats
}

Save your code and run go run main.go

More Resources

There are several solid resources for go the docs page being a great goto

Other tools I like are gobyexample and Learn Go with Tests

Finally, check out the Go Playground and Play with Go

Last updated