Maintain session in golang without using any third party web toolkit or package

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)

}

}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.