Go 1 · Code patterns
HTTP server
Start a web server with only the standard library, using method and path patterns in the router.
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
http.HandleFunc("GET /hello/{name}", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, %s!", r.PathValue("name"))
})
log.Fatal(http.ListenAndServe(":8080", nil))
}