pgstore
pgstore copied to clipboard
Is it normal to call pgstore.NewPGStore for each handlers ?
Hi, in your example you are calling pgstore.NewPGStore inside your handler so:
- Am I supposed to do the same for each handlers which need sessions? So putting this code in each handlers:
store, err := pgstore.NewPGStore("...", []byte("secret-key"))
if err != nil {
log.Fatalf(err.Error())
}
defer store.Close()
defer store.StopCleanup(store.Cleanup(time.Minute * 5))
- If it's not the case I am wondering how are you achieving concurrency if a unique store is accessible by all handlers? I mean how you are ensuring there are no race conditions.
Thank you.
That's an over simplified example, I would create a global (preferably in your server/app struct) and use that where needed.