duanfu6160 2018-03-18 12:39
浏览 106

大猩猩Mux Use()函数不起作用

I want to use the Use() function of the Gorilla Mux package, but I cannot get it to work. It says: r.Use undefined (type *mux.Router has no field or method Use). I used almot the identitcal example from the documentation. My code looks like this.

package main

import (

func simpleMw(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        next.ServeHTTP(w, r)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "hello")

func main() {
    r := mux.NewRouter()
    r.HandleFunc("/", handler)
    http.Handle("/", r)
    http.ListenAndServe(":8000", nil)

You can find the example of the documentation here: http://www.gorillatoolkit.org/pkg/mux#overview, search for "middleware".

I know I could use this method, but I would like to use the Gorilla package.

Many thanks.

  • 写回答

1条回答 默认 最新

  • duanju9104 2018-03-18 12:54

    Thanks to Ivan Velichko, I solved my problem. My package was outdated. I updated it with go get -u github.com/gorilla/mux and now it’s working. Many thanks to y’all!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥20 管道轴向耦合水击问题
  • ¥60 补全networkx TODO部分。
  • ¥15 有内推吗,云计算linux运维方向
  • ¥30 sort cuteSV.vcf by bcftools用IGV可视化出现报错
  • ¥100 SOS!对STK中导出的天体图像进行质心提取有没有人做过啊
  • ¥15 python 欧式距离
  • ¥15 运行qteasy报错
  • ¥15 遗传算法解决有工序顺序约束的大规模FJSP问题
  • ¥15 企业消防水炮塔设计方案
  • ¥20 WORKBENCH网格划分