Quickstart with negroni.Classic()
masterThe negroni.Classic() function is a convenient way to start a server with a set of default middleware: Recovery (to handle panics), Logging (to log requests/responses), and Static (to serve files from a "public" directory).
package main
import (
"fmt"
"net/http"
"github.com/urfave/negroni/v3"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "Welcome to the home page!")
})
n := negroni.Classic() // Includes default middleware
n.UseHandler(mux)
http.ListenAndServe(":3000", n)
}