Closed dilungasr closed 4 years ago
Hi @doctor-windroldev,
Thanks for asking and I am glad that my example gives you a helping hand.
Regarding the session provider, it's a design implementation I made to directly return Fiber's Session pointer.
It allows me to return the Session Store to retrieve stored information, such as the following code to retrieve the stored userid
;
store := providers.SessionProvider().Get(c)
userID, _ := store.Get("userid").(int64)
This was a design choice a few months ago, also Fiber has updated some of its functionalities. I might want to update this project regarding the design choices and to simplify the overall codebase.
Thanks man, you have made it very clear. Waiting for ur updated changes to learn more about structuring my projects.
I will close this issue for now as I started pushing a restructured boilerplate in the develop branch.
I've found your code very useful..Has taught me how to use viper , configuring sessions , auth and so much more! But the problem I face is that I don't understand why you have used something like this...
package providers
import "github.com/gofiber/session"
var sessionP *session.Session
func SessionProvider() *session.Session { return sessionP }
func SetSessionProvider(session *session.Session) { sessionP = session }
and referencing it in the main.go while configuring session in the main.go.
/ Use the Session Middleware if enabled
if config.Enabled["session"] {
// create session handler
providers.SetSessionProvider(session.New(config.Session))
}
Being a newbie I can't figure out the advantage of doing that compared to importing the gofiber/fiber/session and configuring directly. Please try to make it clear to me