1. package main
    2.  
    3. import (
    4. "fmt"
    5. "log"
    6. "net/http"
    7. "time"
    8.  
    9. "github.com/urfave/negroni"
    10.  
    11. func main() {
    12. mux := http.NewServeMux()
    13. mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
    14. fmt.Fprintf(w, "Welcome to the home page!")
    15. })
    16.  
    17. n := negroni.Classic() // 导入一些预设的中间件
    18. n.UseHandler(mux)
    19. s := &http.Server{
    20. Addr: ":8080",
    21. Handler: n,
    22. ReadTimeout: 10 * time.Second,
    23. WriteTimeout: 10 * time.Second,
    24. MaxHeaderBytes: 1 << 20,
    25. }
    26. log.Fatal(s.ListenAndServe())
    27. }