package main
import (
"github.com/julienschmidt/httprouter"
"fmt"
"net/http"
"log"
)
func Index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
fmt.Fprint(w, "Welcome!\n")
}
func Hello(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
fmt.Fprintf(w, "hello, %s!\n", ps.ByName("name"))
}
func MyNotFound(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusNotFound) // StatusNotFound = 404
w.Write([]byte("My own Not Found handler."))
w.Write([]byte(" The page you requested could not be found."))
}
func main() {
router := httprouter.New()
router.GET("/", Index)
router.GET("/hello/:name", Hello)
router.NotFound = http.HandlerFunc(MyNotFound)
log.Fatal(http.ListenAndServe(":8080", router))
}