NJIT's Student Newspaper

The Vector

NJIT's Student Newspaper

The Vector

NJIT's Student Newspaper

The Vector

Tech Tip of the Week: The “Go” Programming Language

Ever hear of the Go (a.k.a “Golang”) Programming Language? If not, you need to check it out! It is perhaps one of the best, newest programming languages out there. What is so good about Go? For starters: it is easy to program, it natively supports networking and multicore computing, it’s fast, and best of all, it’s cool!

Here is a quick example of how to write your own webserver in Go. To run, assuming you have Go installed, just save this as webserver.go and type the command in an editor: go run webserver.go .

Save the following code to a file called webserver.go:

package mainimport (

“fmt”

“net/http”

)

func handler(w http.ResponseWriter, r *http.Request) {

fmt.Fprintf(w, “<html><body>NJIT loves Go!   Visit <a href=http://golang.com>http://golang.com</a> for more info%s!”, r.URL.Path[1:])

}

func main() {

http.HandleFunc(“/”, handler)

http.ListenAndServe(“:8080”, nil)

}

Now run the command:

Go run webserver.go

You just wrote and ran a webserver in Go. Pretty easy right?

Please email any questions regarding this article of the code to [email protected] and also check out http://golang.org for more information on the Go Programming Language.

By Tom Maciejewski

Leave a Comment
Donate to The Vector

Your donation will support the student journalists of New Jersey Institute of Technology. Your contribution will allow us to purchase equipment and cover our annual website hosting costs.

More to Discover
Donate to The Vector

Comments (0)

All The Vector Picks Reader Picks Sort: Newest

Your email address will not be published. Required fields are marked *