Simplest example of web server printing "Hello world" in Go

This is an example Go web server which does nothing but print "Hello world."

package main

import (
    "net/http"
        "log"
)

func reply(rw http.ResponseWriter, req *http.Request) {
    rw.Write([]byte("<html><body><p>Hello world.\n</p></body></html>"))
}

func main() {
    http.HandleFunc("/", reply)
    log.Fatal(http.ListenAndServe(":8082", nil))
}

(download)


Copyright © Ben Bullock 2009-2018. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer