How to maintain session in golang . Right Now i am doing it with the help of cookies which is not safe and better option.
I don’t want to maintain session using gorilla or other third party tool. I want to do it using core. Here is my code.
cookie, err := r.Cookie("session-id")
if err != nil {
cookie = &http.Cookie{
Name: "session-id",
}
}
cookie.Value = r.FormValue("name")
http.SetCookie(w, cookie)
fmt.Println(cookie.Value)
http.Redirect(w, r, "/view", 301)
} else {
message.Message = "Wrong userId or Password"
tmpl.ExecuteTemplate(w, "Index", message)
}
}