我正在尝试从参考中获取地图,并且断言似乎失败了:
session.AddFlash(gin.H{
"username": username,
"password": password,
}, "_post")
...
flashes := session.Flashes("_post")
if flashes != nil {
flash = flashes[0]
fmt.Printf("%T\n", flash)
if post_data, ok := flash.(gin.H); ok {
fmt.Println("post_data:", post_data)
data = post_data
} else {
fmt.Println("post_data(failed):", post_data)
}
}
但是我总是得到以下输出,断言失败:
*gin.H
post_data(failed): map[]
我认为这是由于我正在做的断言,所以我尝试过:
if post_data, ok := (*flash).(gin.H); ok {
但后来我得到 invalid indirect of flash (type interface {})
我也试过:
if post_data, ok := *flash.(gin.H); ok {
但这给了我 invalid indirect of flash.(gin.H) (type gin.H)
鸿蒙传说
慕运维8079593
相关分类