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

Home News Technology 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 etm8@njit.edu and also check out http://golang.org for more information on the Go Programming Language.

By Tom Maciejewski

About The Author

Vector Staff

This article was written by a previous member of the Vector Staff, a member of the Vector who does not have staff privileges, or by multiple authors. Author credentials are given at the bottom of the article.

Leave a Reply

Your email address will not be published.