on 01-Jul-2019 11:47
Go In Plain English: Playing with Strings
Go In Plain English: Creating your First WebServer
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:
Note: If you never programmed in Go, please go straight to the bonus section, install VS Code and come back here!
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.
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:
Inside of it, you create a src directory to keep your *.go source code inside:
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.
When you type go build, Go compiles the executable and saves it to your current directory:
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:
When we type go install, Go creates a bin directory to keep the executable:
In case you want to know what a particular command does, just use go doc command:
The program I use to code in Go and Python is VS Code:
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:
"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!! 🙂
Very nice article! Go and VSCode is a perfect combination.
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.