Answer the question
In order to leave comments, you need to log in
How to work with sessions in golang?
Hello, I ask for help in explaining the principle of working with sessions.
I can not understand the principle of working with sessions (I use Gorilla sessions and redis).
Here for example:
I do authorization of the user. The user enters data, then they are checked against the database, and if everything is correct, then a session should be generated? Suppose we have generated a session, and what's next, roughly speaking, how to understand that Ivan is Ivan and not Kolya?
The next question is, what does "something-very-secret" in the store variable do and why is it needed?
var store = sessions.NewCookieStore([]byte("something-very-secret")) // что это за secret key и зачем он используется
func MyHandler(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session-name")
session.Values["foo"] = "bar"
session.Values[42] = 43
session.Save(r, w)
}
Answer the question
In order to leave comments, you need to log in
The user enters data, then they are checked against the database, and if everything is correct, then a session should be generated?
What for docks to read the truth?
https://godoc.org/gopkg.in/boj/redistore.v1
www.gorillatoolkit.org/pkg/sessions
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question