What version of Go are you using (go version)?
$ go version
go version go1.14.4 darwin/amd64
Does this issue reproduce with the latest release?
In current package documentation at https://golang.org/pkg/net/http/#example_ServeMux_Handle
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
GOARCH="amd64"
GOOS="darwin"
What did you expect to see?
Expected example to initiate http.ListenAndServe or equivalent with new ServeMux
package main
import (
"fmt"
"log"
"net/http"
)
type apiHandler struct{}
func (apiHandler) ServeHTTP(http.ResponseWriter, *http.Request) {}
func main() {
mux := http.NewServeMux()
mux.Handle("/api/", apiHandler{})
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// The "/" pattern matches everything, so we need to check
// that we're at the root here.
if req.URL.Path != "/" {
http.NotFound(w, req)
return
}
fmt.Fprintf(w, "Welcome to the home page!")
})
log.Fatal(http.ListenAndServe(":8080", mux))
}
What did you see instead?
The example immediately exits without serving
package main
import (
"fmt"
"net/http"
)
type apiHandler struct{}
func (apiHandler) ServeHTTP(http.ResponseWriter, *http.Request) {}
func main() {
mux := http.NewServeMux()
mux.Handle("/api/", apiHandler{})
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
// The "/" pattern matches everything, so we need to check
// that we're at the root here.
if req.URL.Path != "/" {
http.NotFound(w, req)
return
}
fmt.Fprintf(w, "Welcome to the home page!")
})
}
I'd be happy to work on this for my first contribution if accepted
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
In current package documentation at https://golang.org/pkg/net/http/#example_ServeMux_Handle
What operating system and processor architecture are you using (
go env)?go envOutputWhat did you expect to see?
Expected example to initiate http.ListenAndServe or equivalent with new ServeMux
package main import ( "fmt" "log" "net/http" ) type apiHandler struct{} func (apiHandler) ServeHTTP(http.ResponseWriter, *http.Request) {} func main() { mux := http.NewServeMux() mux.Handle("/api/", apiHandler{}) mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { // The "/" pattern matches everything, so we need to check // that we're at the root here. if req.URL.Path != "/" { http.NotFound(w, req) return } fmt.Fprintf(w, "Welcome to the home page!") }) log.Fatal(http.ListenAndServe(":8080", mux)) }What did you see instead?
The example immediately exits without serving
package main import ( "fmt" "net/http" ) type apiHandler struct{} func (apiHandler) ServeHTTP(http.ResponseWriter, *http.Request) {} func main() { mux := http.NewServeMux() mux.Handle("/api/", apiHandler{}) mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { // The "/" pattern matches everything, so we need to check // that we're at the root here. if req.URL.Path != "/" { http.NotFound(w, req) return } fmt.Fprintf(w, "Welcome to the home page!") }) }I'd be happy to work on this for my first contribution if accepted