title: "..." undefined ("..." type has no field or method "...")
body: <p>I am setting up crud operations for my go api. After creating all the functions, I get error "app.createApplication undefined (type Application has no field or method createApplication)", although I have created it. </p>
  
  <ul>
  <li>Made sure that variables do not have the same name as existing packages as other questions on stack overflow has stated.</li>
  </ul>
  
  <p>api.go</p>
  
  <pre><code>package controllers
  
  import (
  "encoding/json"
  "fmt"
  "log"
  "net/http"
  "os"
  "strconv"
  "time"
  
  "github.com/gorilla/mux"
  "github.com/jinzhu/gorm"
  _ "github.com/jinzhu/gorm/dialects/postgres"
  _ "github.com/lib/pq"
  _ "gitlab.torq.trans.apps.ge.com/503081542/k-auth-api/models"
  )
  
  var err error
  
  type API struct {
  Database *gorm.DB
  Router   *mux.Router
  }
  
  func (api *API) Initialize(opts string) 
  {
  // Initialize DB
  
  var driver = "postgres"
  var host = os.Getenv("DB_HOST")
  var dbname = os.Getenv("DB_NAME")
  var user = os.Getenv("DB_USER")
  var password = os.Getenv("DB_PASSWORD")
  var port = os.Getenv("DB_PORT")
  var conn = fmt.Sprintf("host=%v dbname=%v user=%v password=%v port=%v sslmode=disable", host, dbname, user, password, port)
  api.Database, err = gorm.Open(driver, conn)
  
  if err != nil {
      log.Print("failed to connect to the database")
      log.Fatal(err)
  }
  
  fmt.Println("Connection estabished")
  
  // Application Model
  
  type Application struct {
      ID        string `json:"id" gorm:"primary_key"`
      AccessId  int64
      CreatedAt time.Time `json:"-"`
      UpdatedAt time.Time `json:"-"`
      Name      string    `json:"name"`
      Ci        string    `json:"ci"`
  }
  
  if !api.Database.HasTable(&amp;Application{}) {
      api.Database.CreateTable(&amp;Application{})
  }
  
  // Initialize Router
  api.Router = mux.NewRouter()
  api.Router.HandleFunc("/api/v1/applications", api.handleApplications)
  api.Router.HandleFunc("/api/v1/application/{id}", api.handleApplication)
  api.Router.HandleFunc("/api/v1/applications", api.getApplications).Methods("GET")
  http.Handle("/", api.Router)
  }
  func (api *API) getApplications(w http.ResponseWriter, r *http.Request) {
  type Application struct {
      ID        string `json:"id" gorm:"primary_key"`
      AccessId  int64
      CreatedAt time.Time `json:"-"`
      UpdatedAt time.Time `json:"-"`
      Name      string    `json:"name"`
      Ci        string    `json:"ci"`
  }
  count, _ := strconv.Atoi(r.FormValue("count"))
  start, _ := strconv.Atoi(r.FormValue("start"))
  
  if count &gt; 10 || count &lt; 1 {
      count = 10
  }
  if start &lt; 0 {
      start = 0
  }
  
  applications, err := getApplications(api.Database, start, count)
  if err != nil {
      respondWithError(w, http.StatusInternalServerError, err.Error())
      return
  }
  
  respondWithJSON(w, http.StatusOK, applications)
  }
  
  func respondWithError(w http.ResponseWriter, code int, message string) {
  respondWithJSON(w, code, map[string]string{"error": message})
  }
  func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
  response, _ := json.Marshal(payload)
  
  w.Header().Set("Content-Type", "application/json")
  w.WriteHeader(code)
  w.Write(response)
  }
  </code></pre>
  
  <p>main.go</p>
  
  <pre><code>package main
  
  import (
      "log"
      "net/http"
  
      "github.com/gorilla/handlers"
      "gitlab.torq.trans.apps.ge.com/503081542/k-auth-api/controllers"
  )
  
  var err error
  
  func main() {
      api := controllers.API{}
      api.Initialize("DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, DB_PORT sslmode=disable connect_timeout=5")
      // api.Initialize("host=%s user=%s password=%s dbname=%s port=%s sslmode=disable connect_timeout=5")
  
      // Bind to a port and pass our router in
      log.Fatal(http.ListenAndServe(":8000", handlers.CORS()(api.Router)))
  
      if err != nil {
          panic(err.Error())
      }
  }
  </code></pre>