3 ms·
From the tour - I've added comments for clarity: // this defines the entry point package main // import formatting and HTTP server packages imp
by eckyptang 14y ago
From the tour - I've added comments for clarity:
// this defines the entry point
package main
// import formatting and HTTP server packages
import (
"fmt"
"net/http"
)
// This is your HTTP Server instance
type Hello struct{}
// This is a method on your HTTP server instance that sends hello for all requests
func (h Hello) ServeHTTP(
w http.ResponseWriter,
r *http.Request) {
fmt.Fprint(w, "Hello!")
}
// this is your entry point
func main() {
// create a new HTTP Server instance
var h Hello
// tell the runtime to serve it
http.ListenAndServe("localhost:4000",h)
}