pgstore icon indicating copy to clipboard operation
pgstore copied to clipboard

Is it normal to call pgstore.NewPGStore for each handlers ?

Open alexisvisco opened this issue 5 years ago • 1 comments

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.

alexisvisco avatar Sep 25 '20 19:09 alexisvisco

That's an over simplified example, I would create a global (preferably in your server/app struct) and use that where needed.

caquillo07 avatar Feb 03 '21 04:02 caquillo07