我正在使用https://github.com/kataras/iris golang网络框架。这是来自此处最后一个问题的后续邮件- 获取登录的用户信息以进行显示-Golang模板
我最终使用的是上一篇文章中提到的代码,例如:
ctx.Values().Get("user")
并且用户设置或拥有的值为“ Struct”类型:-
// 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)
我需要接口的“类型断言”方面的帮助。我如何“键入断言”高于价值?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句