package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
Go is a fast, compiled language with focus on multicore and networked programs. I’ve done a ton of small, fun projects in NodeJS, and love the ease with which I can express small ideas. Unfortunately, I’ve grown out of Node, and am looking for something with better security and scalability. I’ll be writing personal projects in go for the next few months. With Go 2 on the horizon, now seems like a reasonable time to begin learning.
apt install golang
Add to ~/.profile
:
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
The first demo in A Tour of Go gives us insight into how go compiles, links and runs. It should be a lot faster to prototype in go than in c.
package main
import (
"fmt"
"time"
)
func main() {
fmt.Println("Welcome to the playground!")
fmt.Println("The time is", time.Now())
}
main
.import()
is used to bring in packages fmt
and math
.main()
function (hm, no return type?) is executed when the program is run.fmt.Printf()
works similarly to c’s printf
.Interesting things to note:
Parse()
will be available from outside our package, but parse()
will be private.An article on dave.cheney.net and a stack overflow thread
CC BY-SA 4.0 - This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. You are free to share, redistribute and adapt the material as long as appropriate credit is given, and your contributions are distributed under the same license.