- IntelliJ http://go-ide.com/
- Better IntelliJ https://www.jetbrains.com/go/
- Atom https://atom.io/packages/go-plus
- Better Atom https://code.visualstudio.com/
- Emacs https://www.emacswiki.org/emacs/GoLangMode
- Better Emacs https://github.com/fatih/vim-go
Installing: brew install go
Create main.go
file:
package main
import "fmt"
func main() {
fmt.Println("Happy hacking!")
}
Simply run go run main.go
- Grab 10 top stories
- Print title, rating, author to cli of each story
- Write some tests
- Allow to select a particular story in the list
- Display couple of the comments for the selected story
- Allow to go back to the story list
- Add a UI (terminal or gui) using one of these:
Highly recommended to use only stdlib available modules. But no strict rules. Wanna go crazy and pull in dozens of deps? Go for it!
vgo get
is your friend.
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
https://golang.org/pkg/net/http/
resp, err := http.Get("http://example.com/")
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
// body is gonna have []byte type
https://golang.org/pkg/encoding/json/
Into an array:
ids := make([]int, 0)
err := json.Unmarshal(b, &ids)
Into a struct:
type myStruct struct {
Title string `json:"title"`
Author string `json:"author"`
}
func main() {
var body []byte
var data myStruct
....
json.Unmarshal(body, &data)
}
fmt.Printf("This is how you print stuff %s", "in go")
https://golang.org/pkg/testing/
package main
import "testing"
func TestMain(t *testing.T) {
main()
}
subarray := array[0:10]
https://golang.org/pkg/sort/#Slice
Top Stories: https://hacker-news.firebaseio.com/v0/topstories.json
Item: https://hacker-news.firebaseio.com/v0/item/16814671.json
Full api documentation: https://github.com/HackerNews/API/blob/master/README.md
If you decided for some reason to include external dependencies you can do it in 2 ways:
go get github.com/author/project
vgo get github.com/author/project
Vgo is the new versioned dependency tool for golang. go get
will just pull the dependency master branch in to your $GOPATH
(default $GOPATH
value is $HOME/go
), for the sake of this workshop it should also work fine if you dont want to get distracted by dependency managment tools.
Getting started with vgo (if you are planning to use external dependencies only):
go get -u golang.org/x/vgo
export PATH=$PATH:$HOME/go/bin
echo > go.mod
echo 'module "/home/myuser/go/src/workshop-project-name"' > go.mod # is optional
vgo build
./workshop-project-name
Now you can replace go
command with vgo
Fix for vgo requires Go 1.10 but VGOROOT=/usr/lib/go is not a Go 1.10 source tree
:
sudo mkdir /usr/lib/go/api
sudo touch /usr/lib/go/api/go1.10.txt