This blog post is brought to you by the developer of BitBudget. BitBudget is an automated budgeting app for Android and iOS which syncs with your bank account and helps you avoid overspending. If you’d like to quit living paycheck-to-paycheck and get a better handle on your finances, download it today! https://bitbudget.io
I’ve been working with a student of mine recently in Golang and noticed that my skills were sort of lacking! So here’s a quick little cheat sheet reference for coding in Golang. If you need any help getting your computer setup to run Golang, check out Learn Go in 12 Minutes on YouTube.
If you haven’t already installed Golang and set up your environment, do that first…
Step 1: Install Golang
Then, create your “go” directory where you will store all of your golang projects on your local machine:
1
$ cd $HOME
1
$ mkdir go
1
$ cd go
1
$ mkdir src
1
$ cd src
Next, create a subdirectory for your project:
1
$ mkdir hello
1
$ cd hello
Now create a file called hello.go which will contain our hello, world program:
1
2
3
4
5
6
7
package main
import "fmt"
func main() {
fmt.Printf("hello, golang\n")
}
Compile & Run:
1
$ go build
1
$ ./hello
Last, check out the example below (based on Learn Golang in 12 Minutes) as a reference/cheatsheet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Need to work with command line user input? Another cheatsheet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Need to ping a JSON API? More cheatsheet goodness from the folks at RapidAPI:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters