douboshan1466 2019-02-09 10:40
浏览 37
已采纳

Golang包未定义[重复]

I'm trying to install a redistore back end for my Gorilla sessions but I keep getting undefined errors. Here is the documentation I did run go get on the packages but the package import error says that it is imported but not used.

error:

undefined: NewRediStore

code:

package main

import (
...
"github.com/gorilla/sessions"
"gopkg.in/boj/redistore.v1"
)

func main() {

    // Fetch new store.
    store, err := NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))
    if err != nil {
        panic(err)
    }
    defer store.Close()
    ...
}
</div>
  • 写回答

1条回答 默认 最新

  • douyun1546 2019-02-09 10:52
    关注

    You need to qualify imported identifiers by prepending them with the package name which you imported. e.g. packagename.Identifiername.

    Or use . in front of the import to redeclare the exported identifiers of the imported package in the importing file's file block, however keep in mind that this is not a recommended practice.

    import (
        . "gopkg.in/boj/redistore.v1"
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?