Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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
Session Redis会话映射不允许索引_Session_Go_Struct_Redis_Hashmap - Fatal编程技术网

Session Redis会话映射不允许索引

Session Redis会话映射不允许索引,session,go,struct,redis,hashmap,Session,Go,Struct,Redis,Hashmap,我有一个web应用程序,它使用会话结构和组合模型结构 type Session struct { SessionModel } type SessionModel interface { } UserSession是由会话 type UserSession struct { Name string Email string Password string } 当我从Redis解组JSON会话数据时,一个映射存储在SessionModel字段(允许类嵌入的接口)

我有一个web应用程序,它使用会话结构和组合模型结构

type Session struct {
    SessionModel
}
type SessionModel interface { }
UserSession是由
会话

type UserSession struct {
    Name string
    Email string
    Password string
}
当我从Redis解组JSON会话数据时,一个映射存储在SessionModel字段(允许类嵌入的接口)中

我可以访问SessionModel,它的类型是一个映射,但是当我尝试访问索引值时,会出现错误
无效操作:session.SessionModel[“Username”](type sessions.SessionModel不支持索引)
。发生了什么事

reflect.TypeOf(sessions.SessionModel) //map[string]interface {}
session, err := SessionInstance.Get(sessions.Session{sessions.UserSession{}}, cookie.Value)
username := sessions.SessionModel["Username"] //invalid operation: session.SessionModel["Username"] (type sessions.SessionModel does not support indexing)

您是否尝试将
r SessionStore
作为指针
r*SessionStore
?我做了,但没有做任何事情。`SessionModel及其类型是一个map`。没有。SessionModel是
接口{}
的类型,在当前示例中,它包含一个映射,而不是系统性的。因此,在尝试将其用作映射之前,必须首先执行类型断言。我该如何做呢?另外,我说SessionModel是一个映射,因为根据reflect.TypeOf函数,SessionModel就是这样的。
reflect.TypeOf(sessions.SessionModel) //map[string]interface {}
session, err := SessionInstance.Get(sessions.Session{sessions.UserSession{}}, cookie.Value)
username := sessions.SessionModel["Username"] //invalid operation: session.SessionModel["Username"] (type sessions.SessionModel does not support indexing)