Make sure that git binary is in your PATH environment variable.
Make sure that go/bin directory is in your PATH environment variable.
Set the GOPATH
environment variable to point to your workspace directory.
Now you should be able to compile a simple go program. With any text editor create a hello.go file with the following content:
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
To compile the program run the following command in the terminal:
$ go build hello.go
This will create an executable, run it to print "Hello, World!":
$ ./hello
Download IntellijIDEA from https://www.jetbrains.com/idea/
Install Go
plugin and create a new project in $GOPATH/src/github.com/<yourname>/hello
You will be asked to configure the Go SDK while setting up a project.
Let's create a simple http server using "github.com/gorilla/mux" routing library.
Create a main.go file in your new project with the following content:
package main
import (
"fmt"
"github.com/gorilla/mux"
"net/http"
"log"
)
func main() {
router := mux.NewRouter()
router.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, World!")
})
log.Fatal(http.ListenAndServe(":8888", router))
}
IDE will show that gorilla/mux
is not installed, place your cursor on "github.com/gorilla/mux" line and press Alt+Enter, it will suggest installing a package.
After that you should be able to run it from the Run menu.