I was trying to create a go cookie. I want to assign Id from Mongodb to be stored in the Cookie. But while compiling I am getting an error as follows:-
"unknown http.Cookie field 'Id' in struct literal"
The following is my code:-
getUser := user.CheckDB()
expiration := time.Now().Add(365 * 24 * time.Hour)
//The Error is Caused by the Next Line
cookie := http.Cookie{Id: getUser[0].Id, Name: getUser[0].Email, Value: getUser[0].Password, Expires: expiration}
http.SetCookie(w, &cookie)
func (this *User) CheckDB() []User {
var results []User
sess, db := GetDatabase()
defer sess.Close()
c := db.C("user")
uname := &this.Email
err := c.Find(bson.M{"email": *uname}).Sort("-id").All(&results)
if err != nil {
panic(err)
} else {
fmt.Println("Results All: ", results)
return results
}
}
type Cookie struct {
Id bson.ObjectId `bson:"_id,omitempty"`
Name string
Value string
Path string
Domain string
Expires time.Time
RawExpires string
MaxAge int
Secure bool
HttpOnly bool
Raw string
Unparsed []string
}
Thanks in advance.