You need to install GO
Your workspace folder contains three folders: bin, pkg, src
Then you set these four environment variables:
GOARCH= (default architecture you are using: amd64)
GOOS= (default operating system you are using: linux, windows, darwin...)
GOPATH= /path/to/workspace
GOBIN= /path/to/workspace/bin
In your src folder you create subfolders (which are your packages). Convention is /provider/name/repo (github.com/hamster/demo). But you can go as deep as you want.
Then:
Code:
package main
import "net/http"
func main() {
http.HandleFunc("/go/is/awesome", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("You're doing it right"))
})
http.HandleFunc("/but/i/still/use/node", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "trololololol", http.StatusBadRequest)
})
http.ListenAndServe(":8080", nil)
}
To run in your terminal:
To compile to a binary with defaults:
To overide:
Code:
GOOS=windows GOARCH=386 go build main.go
The beauty? You can compile for any environment on the same machine and a binary is always one file. You don't have to worry about a thousand .dll or .jar files and never have to worry about having to install the correct .NET framework, JRE, node or python version.
..and it is fast