title: Runtime panic on calling resource from another package
body: <p>I am trying to create a simple API server using fiber + zap + pgx
  I am getting an error which I am unable to solve.</p>
  <pre><code>PS C:\Users\risharan\Documents\GitHub\freya&gt; go run .\src\freya.go
  panic: runtime error: invalid memory address or nil pointer dereference
  [signal 0xc0000005 code=0x0 addr=0x0 pc=0xcdca67]
  
  goroutine 1 [running]:
  go.uber.org/zap.(*Logger).check(0x0, 0xc000060500, 0xff0b96, 0x15, 0x0)
          C:/Users/risharan/go/pkg/mod/go.uber.org/zap@v1.18.1/logger.go:268 +0x987
  go.uber.org/zap.(*Logger).Info(0x0, 0xff0b96, 0x15, 0x0, 0x0, 0x0)
          C:/Users/risharan/go/pkg/mod/go.uber.org/zap@v1.18.1/logger.go:191 +0x4b
  freya/src/db.Init()
          C:/Users/risharan/Documents/GitHub/freya/src/db/db.go:19 +0x6db
  main.init.0()
          C:/Users/risharan/Documents/GitHub/freya/src/freya.go:15 +0x31
  exit status 2
  </code></pre>
  <p>The code so far is;</p>
  <p>// package main</p>
  <pre><code>func init() {
      logger.Init()
      env.Init()
      db.Init()
  }
  
  func main() {
  
      app := fiber.New()
  
      app.Get(&quot;/&quot;, func(c *fiber.Ctx) error {
          return c.SendString(&quot;Hello, World!&quot;)
      })
  
      log.Fatal(app.Listen(&quot;:3000&quot;))
  }
  </code></pre>
  <p>// package logger</p>
  <pre><code>var Say *zap.Logger
  
  func Init() {
      Say, _ := zap.NewProduction()
      defer Say.Sync()
  }
  </code></pre>
  <p>// package db</p>
  <pre><code>var Conn *pgxpool.Pool
  
  func Init() {
      c, err := pgxpool.Connect(context.Background(), env.Conf[&quot;DATABASE_URL&quot;])
      if err != nil {
          logger.Say.Fatal(&quot;Can't connect to DB&quot;, zap.String(&quot;Details&quot;, err.Error()))
      } else {
          logger.Say.Info(&quot;Connected to Database&quot;)
      }
      Conn = c
  
      defer Conn.Close()
  
      var greeting string
      err = Conn.QueryRow(context.Background(), &quot;select 'Hello, this is db!'&quot;).Scan(&amp;greeting)
      if err != nil {
          logger.Say.Error(&quot;DB Query failed&quot;, zap.String(&quot;Details&quot;, err.Error()))
      }
      logger.Say.Info(&quot;Connected to DB. DB says; &quot;, zap.String(&quot;Details&quot;, greeting))
  
  }
  </code></pre>
  <p>The lines indicated by the error message</p>
  <pre><code>        C:/Users/risharan/Documents/GitHub/freya/src/db/db.go:19 +0x6db
  main.init.0()
          C:/Users/risharan/Documents/GitHub/freya/src/freya.go:15 +0x31
  </code></pre>
  <p>are:</p>
  <pre><code>func init() {
      logger.Init()
      env.Init()
      db.Init() // this is the line 15 as shown in error message in package main
  }
  </code></pre>
  <p>and</p>
  <pre><code>func Init() {
      c, err := pgxpool.Connect(context.Background(), env.Conf[&quot;DATABASE_URL&quot;])
      if err != nil {
          logger.Say.Fatal(&quot;Can't connect to DB&quot;, zap.String(&quot;Details&quot;, err.Error()))
      } else {
          logger.Say.Info(&quot;Connected to Database&quot;) // this is the line 19 in the error message in the package db
      }
  </code></pre>
  <p>So far go's error messages have been hard to decode and I am not sure what am i doing wrong here or what i should do to fix my code.</p>
  <p>Note: I have been told to go for a Dependency Injection arch. I personally find that pattern rather complex, and as I am still learning go, i'd prefer to keep it as simple as I can for now. So would prefer answers to not advise me to switch patterns, unless it is not possible to fix the current global variable based pattern.</p>