- package main
- import (
- "fmt"
- "log"
- "net/http"
- "time"
- "github.com/urfave/negroni"
- 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() // 导入一些预设的中间件
- n.UseHandler(mux)
- s := &http.Server{
- Addr: ":8080",
- Handler: n,
- ReadTimeout: 10 * time.Second,
- WriteTimeout: 10 * time.Second,
- MaxHeaderBytes: 1 << 20,
- }
- log.Fatal(s.ListenAndServe())
- }