-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cross Web Server Session #87
Comments
@CasperHK That's what you get by default with cookies: as long as servers are all part of the same domain (e.g. github.com, or *.github.com) then the cookie will be sent by the browser. Alternatively, sessions also supports server-side stores - all servers would need to be able to connect to that store (be it Redis, or PostgreSQL, etc). |
|
Use the default CookieStore, and if all servers have the same signing key, On Sun, Jul 24, 2016 at 10:48 PM Casper LI notifications@github.com wrote:
|
Sorry, I want to ask what the default CookieStore and the signing key are? CookieStore means |
Yes. Take a look at http://www.gorillatoolkit.org/pkg/sessions -
import (
"net/http"
"github.com/gorilla/sessions"
)
var store = sessions.NewCookieStore([]byte("something-very-secret"))
func MyHandler(w http.ResponseWriter, r *http.Request) {
// Get a session. We're ignoring the error resulted from decoding an
// existing session: Get() always returns a session, even if empty.
session, err := store.Get(r, "session-name")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Set some session values.
session.Values["foo"] = "bar"
session.Values[42] = 43
// Save it before we write to the response/return from the handler.
session.Save(r, w)
} |
Inject store (sessions.Store) as a dependency into your other packages. On Mon, Jul 25, 2016 at 8:57 AM Casper LI notifications@github.com wrote:
|
https://godoc.org/github.com/gorilla/sessions#NewCookieStore
|
Sorry, Iam quite new to Go. Could you explain more about |
@CasperHK Have your packages' constructors accept their dependencies - e.g.
In func main() {
// Create a store, and then pass it (inject it) into your other packages via their constructors
store := sessions.NewCookieStore(key)
...
ce, err := package.NewCodeEditor(store)
...
pb, err := package.NewProjectBrowser(store)
...
} |
Closing due to inactivity. |
It is possible to make a cross server session by using gorilla/sessions? Assume that I have multiple servers to serve one website. If the user login in one server, I expect he also login in other server.
The text was updated successfully, but these errors were encountered: