“…” undefined (“…” type has no field or method “…”)












-3














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.




  • Made sure that variables do not have the same name as existing packages as other questions on stack overflow has stated.


api.go



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(&Application{}) {
api.Database.CreateTable(&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 > 10 || count < 1 {
count = 10
}
if start < 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)
}


main.go



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())
}
}









share|improve this question




















  • 1




    Hundreds of lines of unformatted code is not going to help the community assist you with this. Please reduce this to a Minimal, Complete, Verifiable Example demonstrating just the issue you're having, run gofmt on it, and update your question.
    – Adrian
    Dec 27 '18 at 15:17






  • 2




    The error message is about is clear as it can be: the type Application does not have a createApplication method. The API type does have a createApplication method. Perhaps you meant to call that.
    – ThunderCat
    Dec 27 '18 at 15:33










  • Okay I have condensed it to just the "getApplications" function.
    – Khaled Aman
    Dec 27 '18 at 15:41
















-3














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.




  • Made sure that variables do not have the same name as existing packages as other questions on stack overflow has stated.


api.go



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(&Application{}) {
api.Database.CreateTable(&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 > 10 || count < 1 {
count = 10
}
if start < 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)
}


main.go



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())
}
}









share|improve this question




















  • 1




    Hundreds of lines of unformatted code is not going to help the community assist you with this. Please reduce this to a Minimal, Complete, Verifiable Example demonstrating just the issue you're having, run gofmt on it, and update your question.
    – Adrian
    Dec 27 '18 at 15:17






  • 2




    The error message is about is clear as it can be: the type Application does not have a createApplication method. The API type does have a createApplication method. Perhaps you meant to call that.
    – ThunderCat
    Dec 27 '18 at 15:33










  • Okay I have condensed it to just the "getApplications" function.
    – Khaled Aman
    Dec 27 '18 at 15:41














-3












-3








-3







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.




  • Made sure that variables do not have the same name as existing packages as other questions on stack overflow has stated.


api.go



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(&Application{}) {
api.Database.CreateTable(&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 > 10 || count < 1 {
count = 10
}
if start < 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)
}


main.go



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())
}
}









share|improve this question















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.




  • Made sure that variables do not have the same name as existing packages as other questions on stack overflow has stated.


api.go



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(&Application{}) {
api.Database.CreateTable(&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 > 10 || count < 1 {
count = 10
}
if start < 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)
}


main.go



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())
}
}






go crud






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 '18 at 21:11

























asked Dec 27 '18 at 15:13









Khaled Aman

32




32








  • 1




    Hundreds of lines of unformatted code is not going to help the community assist you with this. Please reduce this to a Minimal, Complete, Verifiable Example demonstrating just the issue you're having, run gofmt on it, and update your question.
    – Adrian
    Dec 27 '18 at 15:17






  • 2




    The error message is about is clear as it can be: the type Application does not have a createApplication method. The API type does have a createApplication method. Perhaps you meant to call that.
    – ThunderCat
    Dec 27 '18 at 15:33










  • Okay I have condensed it to just the "getApplications" function.
    – Khaled Aman
    Dec 27 '18 at 15:41














  • 1




    Hundreds of lines of unformatted code is not going to help the community assist you with this. Please reduce this to a Minimal, Complete, Verifiable Example demonstrating just the issue you're having, run gofmt on it, and update your question.
    – Adrian
    Dec 27 '18 at 15:17






  • 2




    The error message is about is clear as it can be: the type Application does not have a createApplication method. The API type does have a createApplication method. Perhaps you meant to call that.
    – ThunderCat
    Dec 27 '18 at 15:33










  • Okay I have condensed it to just the "getApplications" function.
    – Khaled Aman
    Dec 27 '18 at 15:41








1




1




Hundreds of lines of unformatted code is not going to help the community assist you with this. Please reduce this to a Minimal, Complete, Verifiable Example demonstrating just the issue you're having, run gofmt on it, and update your question.
– Adrian
Dec 27 '18 at 15:17




Hundreds of lines of unformatted code is not going to help the community assist you with this. Please reduce this to a Minimal, Complete, Verifiable Example demonstrating just the issue you're having, run gofmt on it, and update your question.
– Adrian
Dec 27 '18 at 15:17




2




2




The error message is about is clear as it can be: the type Application does not have a createApplication method. The API type does have a createApplication method. Perhaps you meant to call that.
– ThunderCat
Dec 27 '18 at 15:33




The error message is about is clear as it can be: the type Application does not have a createApplication method. The API type does have a createApplication method. Perhaps you meant to call that.
– ThunderCat
Dec 27 '18 at 15:33












Okay I have condensed it to just the "getApplications" function.
– Khaled Aman
Dec 27 '18 at 15:41




Okay I have condensed it to just the "getApplications" function.
– Khaled Aman
Dec 27 '18 at 15:41












2 Answers
2






active

oldest

votes


















0














if err := app.createApplication(api.Database); err != nil {


Your var app has Application type but method createApplication linked with API type. I cannot find createApplication method for Application in the code.






share|improve this answer





















  • Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
    – Khaled Aman
    Dec 27 '18 at 16:23










  • “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
    – Khaled Aman
    Dec 27 '18 at 16:24










  • I posted this answer as a comment since the code does not format correctly.
    – Khaled Aman
    Dec 27 '18 at 18:15





















0














Making some progress. I added the following code as the “getApplication” method. No longer getting the previous error, now getting error listed below.



func (app *Application) getApplication(api.Database) {
if err := app.getApplication(api.Database); err != nil {
respondWithError("Error getting Application")
return
}


Error:




  • [go] Undefined: Application

  • [go] Undefined: api






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53947175%2fundefined-type-has-no-field-or-method%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    if err := app.createApplication(api.Database); err != nil {


    Your var app has Application type but method createApplication linked with API type. I cannot find createApplication method for Application in the code.






    share|improve this answer





















    • Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
      – Khaled Aman
      Dec 27 '18 at 16:23










    • “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
      – Khaled Aman
      Dec 27 '18 at 16:24










    • I posted this answer as a comment since the code does not format correctly.
      – Khaled Aman
      Dec 27 '18 at 18:15


















    0














    if err := app.createApplication(api.Database); err != nil {


    Your var app has Application type but method createApplication linked with API type. I cannot find createApplication method for Application in the code.






    share|improve this answer





















    • Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
      – Khaled Aman
      Dec 27 '18 at 16:23










    • “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
      – Khaled Aman
      Dec 27 '18 at 16:24










    • I posted this answer as a comment since the code does not format correctly.
      – Khaled Aman
      Dec 27 '18 at 18:15
















    0












    0








    0






    if err := app.createApplication(api.Database); err != nil {


    Your var app has Application type but method createApplication linked with API type. I cannot find createApplication method for Application in the code.






    share|improve this answer












    if err := app.createApplication(api.Database); err != nil {


    Your var app has Application type but method createApplication linked with API type. I cannot find createApplication method for Application in the code.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 27 '18 at 15:32









    Maxim Shubin

    96610




    96610












    • Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
      – Khaled Aman
      Dec 27 '18 at 16:23










    • “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
      – Khaled Aman
      Dec 27 '18 at 16:24










    • I posted this answer as a comment since the code does not format correctly.
      – Khaled Aman
      Dec 27 '18 at 18:15




















    • Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
      – Khaled Aman
      Dec 27 '18 at 16:23










    • “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
      – Khaled Aman
      Dec 27 '18 at 16:24










    • I posted this answer as a comment since the code does not format correctly.
      – Khaled Aman
      Dec 27 '18 at 18:15


















    Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
    – Khaled Aman
    Dec 27 '18 at 16:23




    Here are the errors in the console. How would a method for a get request? 1. app.createApplication undefined (type Application has no field or method createApplication) 2. app.getApplication undefined (type Application has no field or method getApplication) 3. app.updateApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method updateApplication) 4. app.deleteApplication undefined (type "gitlab.torq.trans.apps.ge.com/torq/torq-auth-api/models".Application has no field or method deleteApplication)
    – Khaled Aman
    Dec 27 '18 at 16:23












    “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
    – Khaled Aman
    Dec 27 '18 at 16:24




    “App” is pointing to the Application struct, and “api” is pointing to the *API struct. Not exactly sure what is missing. I have tried doing something like this but still get the error. func (app *Application) createApplication(db *gorm.DB) string { return (“Works”) }
    – Khaled Aman
    Dec 27 '18 at 16:24












    I posted this answer as a comment since the code does not format correctly.
    – Khaled Aman
    Dec 27 '18 at 18:15






    I posted this answer as a comment since the code does not format correctly.
    – Khaled Aman
    Dec 27 '18 at 18:15















    0














    Making some progress. I added the following code as the “getApplication” method. No longer getting the previous error, now getting error listed below.



    func (app *Application) getApplication(api.Database) {
    if err := app.getApplication(api.Database); err != nil {
    respondWithError("Error getting Application")
    return
    }


    Error:




    • [go] Undefined: Application

    • [go] Undefined: api






    share|improve this answer




























      0














      Making some progress. I added the following code as the “getApplication” method. No longer getting the previous error, now getting error listed below.



      func (app *Application) getApplication(api.Database) {
      if err := app.getApplication(api.Database); err != nil {
      respondWithError("Error getting Application")
      return
      }


      Error:




      • [go] Undefined: Application

      • [go] Undefined: api






      share|improve this answer


























        0












        0








        0






        Making some progress. I added the following code as the “getApplication” method. No longer getting the previous error, now getting error listed below.



        func (app *Application) getApplication(api.Database) {
        if err := app.getApplication(api.Database); err != nil {
        respondWithError("Error getting Application")
        return
        }


        Error:




        • [go] Undefined: Application

        • [go] Undefined: api






        share|improve this answer














        Making some progress. I added the following code as the “getApplication” method. No longer getting the previous error, now getting error listed below.



        func (app *Application) getApplication(api.Database) {
        if err := app.getApplication(api.Database); err != nil {
        respondWithError("Error getting Application")
        return
        }


        Error:




        • [go] Undefined: Application

        • [go] Undefined: api







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 27 '18 at 20:16

























        answered Dec 27 '18 at 18:18









        Khaled Aman

        32




        32






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53947175%2fundefined-type-has-no-field-or-method%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'