Skip to content
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

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

Open
alexisvisco opened this issue Sep 25, 2020 · 1 comment
Open

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

alexisvisco opened this issue Sep 25, 2020 · 1 comment

Comments

@alexisvisco
Copy link

alexisvisco commented Sep 25, 2020

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 alexisvisco changed the title Is it normal to create a pgstore.NewPGStore for each handlers ? Is it normal to call a pgstore.NewPGStore for each handlers ? Sep 25, 2020
@alexisvisco alexisvisco changed the title Is it normal to call a pgstore.NewPGStore for each handlers ? Is it normal to call pgstore.NewPGStore for each handlers ? Sep 25, 2020
@caquillo07
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants