title: Can't define receiver from another package in Go
body: <p>I'm a beginner in Golang and can't understand some concepts in this language. I like it very much, but every examples on the web are very simple and not explain the correct way of developing.<br>
  I want to configure db connection with MySQL. I create a package <code>dbconfig</code> with file dbconfig.go and package dastructure with interfaces files and another package <code>entity</code> with entities files.<br>
  This is the structure:
  [<img src="https://i.stack.imgur.com/Ddkhl.png" alt="1]"></p>
  
  <p><strong>main.go:</strong></p>
  
  <pre><code>import (
      y "github.com/danyalov/shebeke/dbconfig"
      "github.com/danyalov/shebeke/routes"
      _ "github.com/go-sql-driver/mysql"
      "github.com/labstack/gommon/log"
  )
  
  func main() {
      db, err := y.InitDB("mysql", "root:root@tcp(localhost:3306)/dbtest?parseTime=true")
      if err != nil {
          log.Fatal(err)
      }
      e := routes.NewConnection(db)
      e.Logger.Fatal(e.Start(":9898"))
  }
  </code></pre>
  
  <p><strong>routes.go:</strong></p>
  
  <pre><code>import (
      "github.com/danyalov/shebeke/datastructure"
      y "github.com/danyalov/shebeke/dbconfig"
      "github.com/labstack/echo"
      "github.com/labstack/echo/middleware"
  )
  
  func NewConnection(db *y.DB) *echo.Echo {
      e := echo.New()
      env := Env{db}
      e.Use(middleware.Logger())
      e.Use(middleware.Recover())
  
      e.GET("/contracts", env.GetContracts)
      e.GET("/contract/:id", env.GetContractByID)
  
      return e
  }
  
  type Env struct {
      contract datastructure.Contract
  }
  </code></pre>
  
  <p><strong>services.go:</strong></p>
  
  <pre><code>import (
      "github.com/labstack/echo"
      "log"
      "net/http"
      "strconv"
  )
  
  func (env *Env) GetContracts(c echo.Context) error {
      contracts, err := env.contract.GetContracts()
      if err != nil {
          log.Fatal(err)
      }
      return c.JSON(http.StatusOK, &amp;contracts)
  }
  </code></pre>
  
  <p><strong>dbconfig.go:</strong></p>
  
  <pre><code>import (
      "database/sql"
      "fmt"
      "github.com/labstack/gommon/log"
  )
  
  type DB struct {
      *sql.DB
  }
  
  //InitDB initialize mysql database
  func InitDB(driver, path string) (*DB, error) {
      db, err := sql.Open(driver, path)
      if err != nil {
          log.Fatal(err)
      }
      err = db.Ping()
      if err != nil {
          log.Fatal(err)
      } else {
          fmt.Println("Connected to DB")
      }
      return &amp;DB{db}, err
  }
  </code></pre>
  
  <p><strong>datastructure/contract.go:</strong></p>
  
  <pre><code>import y "github.com/danyalov/shebeke/datastructure/entity"
  
  type Contract interface {
      GetContracts() (y.Contracts, error)
      GetContractByID(id int) (y.Contract, error)
  }
  </code></pre>
  
  <p><strong>datastructure/entity/contract.go:</strong></p>
  
  <pre><code>import (
      "github.com/labstack/gommon/log"
      "time"
  )
  
  type Contract struct {
      ID         int       `json:"id"`
      State      string    `json:"state"`
      StartDate  time.Time `json:"start_date"`
      FinishDate time.Time `json:"finish_date"`
  }
  
  type Contracts []Contract
  
  func (db *DB) GetContracts() (c Contracts, err error) {
      rows, err := db.Query("select * from contract")
      if err != nil {
          log.Fatal(err)
      }
  
      contract := Contract{}
      for rows.Next() {
          err = rows.Scan(&amp;contract.ID, &amp;contract.State, &amp;contract.StartDate, &amp;contract.FinishDate)
          c = append(c, contract)
      }
      return c, err
  }
  </code></pre>
  
  <p>Why can't I import <code>DB</code> type from <code>dbconfig</code> package into <code>entity</code> package as a method receiver? I get <code>Unresolved type 'DB'</code> error.</p>
  
  <p>This is <a href="https://github.com/danyalov/shebeke" rel="noreferrer">my working copy(Git)</a> of this project, I put <code>dbconfig.go</code> inside the entity, but I don't like it, I think it's incorrect place for <code>dbconfig</code> file.</p>
  
  <p>What is the correct file structure for configuring db in Go? Maybe you have your own examples in Git or some tutorial?</p>