golang XXX undefined (type interface {} is interface with no methods)

3030 단어 goLangbeego
XXX undefined (type interface {} is interface with no methods) 해결
type User struct {
     
	Name string 
	Age int 
}
data := User{
     
	Name: "zs",
	Age: 18,
}
//  session
SetSession("user", data)
//  session
userInfo := GetSession("user")
//  :
age := userInfo.Age 
fmt.PrintIn(age)
// error:userInfo.Age undefined (type interface {} is interface with no methods)

해결 방법 1
//  :
age := userInfo.(User).Age
fmt.PrintIn(age)
// 18

해결 방법 2
//  :
userInfo := (GetSession("user")).(User)
age := userInfo.Age
fmt.PrintIn(age)
// 18

좋은 웹페이지 즐겨찾기