title: Golang how can I do a Dependency Injection to store some string values
body: <p>I am using a mysql database and have many different Functions/Methods that interact with the database. For every Function I offcourse have to supply the Database Credentials such as </p>
  
  <p><em>ReadAll.go</em></p>
  
  <pre><code>func ReadAll() {
      db, err := sql.Open("mysql",
          "user:password@tcp(127.0.0.1:3306)/hello")
      if err != nil {
          log.Fatal(err)
      }
      defer db.Close()
  }
  </code></pre>
  
  <p>The part of <strong>"mysql",
              "user:password@tcp(127.0.0.1:3306)/hello"</strong> never changes and I am supplying that to every Function that interacts with DB. I was wondering how can I for instance create a new File say <em>DataBase.go</em> put those credentials into some global variable and then reference when I need those strings ? That way if I have to change the credentials I only have to change them in 1 place.
  I want to do something like</p>
  
  <p><em>Database.go</em></p>
  
  <pre><code>const GlobalDB := "mysql","user:password@tcp(127.0.0.1:3306)/hello"
  </code></pre>
  
  <p>then </p>
  
  <p>ReadAll.go</p>
  
  <pre><code>func ReadAll() {
      db, err := sql.Open(GlobalDB)
      if err != nil {
          log.Fatal(err)
      }
      defer db.Close()
  }
  </code></pre>
  
  <p>I am brand new to Golang but trying to figure this out.</p>