Answer the question
In order to leave comments, you need to log in
How to use a variable from main.go in another package?
Hello!
I just started learning Golang, I have a question.
I have 2 files in 2 different packages, simplified version below:
package main:
func main() {
var globalSessions, _ = session.NewManager("memory", conf)
go globalSessions.GC()
}
func test(){
sess, _ := globalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
}
Answer the question
In order to leave comments, you need to log in
So you are unlikely to succeed, but there is such an option:
admin.go:
var GlobalSessions *session.Manager
func test(){
sess, _ := GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
}
func main() {
var globalSessions, _ = session.NewManager("memory", conf)
go globalSessions.GC()
admin.GlobalSessions = globalSessions
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question