I created a user entry in my gorilla session
session.Values["ub"] = ub
However when I am extracting, the extracted interface is getting the value but when I am type-asserting the data into my user structure it is showing null.
I am not getting the reason behind this, as when I am running the same code with other structures, it is working fine. What could be the reason and how to fix this.
val := session.Values["ub"]
var ub = &UserBasic{}
var ok bool
if val != "" {
//type assertion
//var userBasic = &auth.UserBasic{}
ub, ok = val.(*UserBasic)
if !ok {
// Handle the case that it's not an expected type
log.Infof(ctx, "GetUserGSession: UserBasic structure value %+v", ub)
log.Infof(ctx, "GetUserGSession: Value got from session %+v", val)
log.Infof(ctx, "GetUserGSession: reasserting %+v", val.(UserBasic))
}
return ub
} else {
ub := new(UserBasic)
return ub
}
*********Outcome************
2016/08/01 03:49:12 INFO: GetUserGSession: UserBasic structure value <nil>
2016/08/01 03:49:12 INFO: GetUserGSession: Value got from session {UserID:589578337 UserName:ds Name:ds createdAt:{sec:0 nsec:0 loc:<nil>} defaultProfileImage:false description: FavouritesCount:5 FollowersCount:0 FriendsCount:0 TotalTweets:6 ListedCount:0 Location: ProfileBgColor: ProfileBgImgURL: ProfileImgURL: IsLoggedIn:true TimeZone:}
2016/08/01 03:49:12 INFO: GetUserGSession: reasserting {UserID:589578337 UserName:ds Name:ds createdAt:{sec:0 nsec:0 loc:<nil>} defaultProfileImage:false description: FavouritesCount:5 FollowersCount:0 FriendsCount:0 TotalTweets:6 ListedCount:0 Location: ProfileBgColor: ProfileBgImgURL: ProfileImgURL: IsLoggedIn:true TimeZone:}