
Let’s set up GO lang on Raspberry Pi. I’m going to install GO on Raspberry Pi 3 B+. At first, I’m login to pi using SSH over wifi and run the following commands to install GO… by running following command >> “sudo apt-get install golang” . Once install completed, then run “go version” to check the go version and verify the install.

Now create a file server.go by typing >> “touch server.go” and write the following code. Once we run the server.go , then it will print out the “Hello,বাংলাদেশ”
package main
import “fmt”
func main() {
fmt.Println(“Hello,বাংলাদেশ”)
}

Cool! here is the 1st step of GO lang on raspberry pi. Now we will enhance the functionality in our code to do some more things. Let’s create a go server and exposed working directory over http using FileServer. Here is the Github link for the code.
package main
import (
“fmt”
“log”
“net/http”
)
func main() {
fmt.Println(“Hello,বাংলাদেশ”)
http.Handle(“/”, http.FileServer(http.Dir(“.”)))
log.Printf(“Starting httpweb Server on port 3005”)
log.Fatal(http.ListenAndServe(“:3005”, nil))
}
Now run the go server again by following command >> “go run server.go”

To test this go server, we need to visit http://<rapberrypi-IP>:3005/

If we want to run this server in the background without interrupting, then it’s easy to start the server using nohup command as below >> “nohup go run server.go &”. This will allow us to do other things in raspberry pi, while this server will keep running...

Now we will check the go environment setting by running the command “go env” and update “GOPATH”. As you can set we did not configure the GOPATH yet.

By running the following command we can set the PATH variable to profile .
pi@raspberrypi:~/go $ echo ‘export GOPATH=$HOME/go’ >> ~/.profile
pi@raspberrypi:~/go $ echo ‘PATH=”$HOME/go/bin:$PATH”’ >> ~/.profile

To see the changes we have to logout & login again. Here now we can see the GOPATH set to “/home/pi/go” directory.

As the path variable set, now we can fetch the go raspicam package. But I encountered the following error as git was not installed. To install git we need to run “sudo apt-get install git"pkg will contain all compiled packages that can be imported into our projects.

Once git installed successfully then get the raspicam package “go get github.com/dhowden/raspicam”
Now copy the sample code from the raspicam package and start the TCP server by the following command .

Next…Enhancement coming soon!
