NotFoundHandler in Go

Posted by GoDoc
Public (Editable by Users)

NotFoundHandler returns a simple request handler that replies to each request with a “404 page not found” reply.

Go
Edit
package main

import (
	"log"
	"net/http"
)

func main() {
	mux := http.NewServeMux()

	// Create sample handler to returns 404
	mux.Handle("/resources", http.NotFoundHandler())

	// Create sample handler that returns 200
	mux.Handle("/resources/people/", newPeopleHandler())

	log.Fatal(http.ListenAndServe(":8080", mux))
}