[Solved] Golang import struct and share over all app


enter image description here

you might want to solve this like:

// main.go
import "testapp/app"
func main(){
    a := app.GetApp()
    err := a.ConnectDatabase()
    if err != nil {
        panic(err.Error())
    }
    a.db. //interesting db code here
}

// testapp/app.go
func (a *App) ConnectDatabase() error{
  db, err := sql.Open()
  if err != nil {
    return err
  }
  a.db = db
  return nil
}

solved Golang import struct and share over all app