0
我正在使用https://github.com/kataras/iris golang web框架。这是最后一个问题问这里跟进邮件 - Fetching Logged in User Info for display - Golang Template类型interface {}是没有方法的接口 - Golang
我终于用代码,在以前的帖子就像提到: -
ctx.Values().Get("user")
和用户设置或具有价值是“结构”类型: -
// users is struct below
var user users
// details are fetched from DB and assigned to user
// like mentioned here http://go-database-sql.org/retrieving.html
// Now value is set
ctx.Values().Set("user", user);
但所获得的价值后,当我在不同的处理程序和打印使用: -
user := ctx.Values().Get("user")
fmt.Println(user.ID)
我得到的错误: -
user.ID undefined (type interface {} is interface with no methods)
我需要在 “类型断言” 为界面帮助。我怎样才能“键入断言”以上价值。
请让我知道,什么是正确的做法。 谢谢
[Golang类型接口{}的可能重复是没有方法的接口](https://stackoverflow.com/questions/32277884/golang-type-interface-is-interface-with-no-methods) –