Jayanta Paul
Nov 4 · 3 min read

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/

Fig: Browsing raspberry pi working directory over HTTP

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 packagego 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!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade