Go http.Handler - Hello world

$ mkdir hello; cd hello/

Create and edit file hello_world.go


package main

import (
	"fmt"
	"log"
	"net/http"
)

func main() {
	err := http.ListenAndServe(":8080", helloWorld())
	if err != nil {
		log.Fatal(err)
	}
}

func helloWorld() http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, "Hello world")
	}
}

References: net/http, http.ListenAndServe, http.HandlerFunc and log.Fatal

Compile and execute your command

$ go run .