Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gorilla Mux Use()函数不起作用_Go_Gorilla_Mux - Fatal编程技术网

Gorilla Mux Use()函数不起作用

Gorilla Mux Use()函数不起作用,go,gorilla,mux,Go,Gorilla,Mux,我想使用Gorilla Mux包的use()函数,但无法使其正常工作。它说:r.Use undefined(type*mux.Router没有字段或方法Use)。我使用了文档中的标识示例。我的代码看起来像这样 package main import ( "net/http" "github.com/gorilla/mux" "fmt" ) func simpleMw(next http.Handler) http.Handler { return http.H

我想使用Gorilla Mux包的use()函数,但无法使其正常工作。它说:
r.Use undefined(type*mux.Router没有字段或方法Use)
。我使用了文档中的标识示例。我的代码看起来像这样

package main

import (
    "net/http"
    "github.com/gorilla/mux"
    "fmt"
)

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

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

func main() {
    r := mux.NewRouter()
    r.HandleFunc("/", handler)
    r.Use(simpleMw)
    http.Handle("/", r)
    http.ListenAndServe(":8000", nil)
}
您可以在这里找到文档示例:,搜索“中间件”

我知道我可以使用这个方法,但我想使用Gorilla软件包


非常感谢。

多亏了伊万·维利科,我解决了我的问题。我的包裹过时了。我用
go-get-u github.com/gorilla/mux
更新了它,现在它开始工作了。非常感谢你们

为什么不使用negroni来处理中间件呢?这个代码对我很有用。你用什么版本的大猩猩?哈!你是对的。可能是很旧的。我用
go-get-u
更新了我的Gorilla包,现在它开始工作了。非常感谢!!