Technical Articles
F5 SMEs share good practice.
cancel
Showing results for 
Search instead for 
Did you mean: 

Related Articles:

Go In Plain English: Playing with Strings

Go In Plain English: Creating your First WebServer

Quick Intro

I like to keep things short so just do what I do here and you will pick things up.

In this article we'll cover the following:

  • Installation (1 liner) 
  • Hello world!
  • The directory structure of Go
  • BONUS! VS Code for Golang

Installation

→ https://golang.org/doc/install

Note: If you never programmed in Go, please go straight to the bonus section, install VS Code and come back here!

Hello World!

0151T000003kSf4QAE.png

At the moment just keep in mind that you'll typically see package, import and func in a Go program.

If you're just getting started then this is not the time to go really in-depth but package main signals go that our piece of code is an executable.

The import statement is where you tell go which additional package you'd like to import. In this case, we're importing fmt package (the one that has the Printf method).

Lastly, func main() is where you're going to add your code to, i.e. the entry point of our program.

Running your Go code!

You can pick a folder of your choice to run your Go apps.

In my case I picked /Users/albuquerque/Documents/go-apps/ directory here:

0151T000003kSfJQAU.png

Inside of it, you create a src directory to keep your *.go source code inside:

0151T000003kShKQAU.png

go run 

When you type go run you're telling Go that you don't care about executable (for now) so go compiles your code, keeps executable into a temporary directory and runs it for you.

0151T000003kShUQAU.png

go build

When you type go build, Go compiles the executable and saves it to your current directory:

0151T000003kSheQAE.png

go install

There is a variable called $GOPATH where we tell Go where to look for source files. Let's set it to our go-apps directory:

0151T000003kShoQAE.png

When we type go install, Go creates a bin directory to keep the executable:

0151T000003kShyQAE.png

go doc

In case you want to know what a particular command does, just use go doc command:

0151T000003kSiDQAU.png

BONUS! VS Code for Golang

The program I use to code in Go and Python is VS Code:

0151T000003kSiXQAU.png

It has autocompletion and roughly all you expect from a proper code editor.

You can download it from here: https://code.visualstudio.com/download

You can choose themes too:

0151T000003kSicQAE.png

Comments
Andy_McGrath
Cumulonimbus
Cumulonimbus

"all you expect from a proper code editor."

 

That's because it is a proper code editor, the best in the world (after vim) 😉

True, Andy!! 🙂

Cyro_Dubeux
Nimbostratus
Nimbostratus

Very nice article! Go and VSCode is a perfect combination.

Tom_Schaefer
Altostratus
Altostratus

I feel like I missed an announcement. How is Go used in F5 products?

Tom, this article is just a general Go article, not specifically related to any F5 product.

 

Cheers,

Rodrigo

Version history
Last update:
‎01-Jul-2019 11:47
Updated by:
Contributors