Here is my code about a little example webserver with golang and mux :
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func handler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
fmt.Fprintf(w, "Hi there, I love %s!", vars["username"])
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" {
errorHandler(w, r, http.StatusNotFound)
return
}
vars := mux.Vars(r)
fmt.Fprintf(w, "Hi there, I love %s!", vars["username"])
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/help/{username}/", handler)
http.Handle("/", r)
http.ListenAndServe(":8080", nil)
}
But I don't find a way on how to do a custom 404 page, i would like to make a custom 404.
But I can't make a r.HandleFunc("/",...) but it will be too greedy.
If anyone have any idea.