我正在使用大猩猩多路复用器来管理路由.我缺少的是在每个请求之间集成一个中间件.
例如
package main
import (
"fmt"
"github.com/gorilla/mux"
"log"
"net/http"
"strconv"
)
func HomeHandler(response http.ResponseWriter, request *http.Request) {
fmt.Fprintf(response, "Hello home")
}
func main() {
port := 3000
portstring := strconv.Itoa(port)
r := mux.NewRouter()
r.HandleFunc("/", HomeHandler)
http.Handle("/", r)
log.Print("Listening on port " + portstring + " ... ")
err := http.ListenAndServe(":"+portstring, nil)
if err != nil {
log.Fatal("ListenAndServe error: ", err)
}
}
每个传入的请求都应该通过中间件.我怎样才能在这里集成一个中间件呢?
Update
我会将它与大猩猩/会话结合使用,他们会说:
重要提示:如果你没有使用gorilla/mux,你需要包装你的
我如何才能防止这种情况发生?