I have a main.go file which has:
// running the router in port 9000
func main() {
router,Global := routers.InitApp()
fmt.println(Global)
router.RunTL
It is better to use the init function for initialisation of global variables. It also will be processed only once even in multiply includes of this package. https://play.golang.org/p/0PJuXvWRoSr
package main
import (
"fmt"
)
var Global string
func init() {
Global = InitApp()
}
func main() {
fmt.Println(Global)
}
func InitApp() (string) {
return "myvalue"
}