Post API getting invalid character '-' in numeric literal

by Meliodas   Last Updated July 13, 2019 01:26 AM

I'm trying to make a POST function to insert data in my database using go.

My Model:

type Funcstruct {
    Name      string `json:"Name"`
    Status    string `json:"Status"`
}

My post function:

//POST FUNC
func (app *App) createFunc(w http.ResponseWriter, r *http.Request) {

    decoder := json.NewDecoder(r.Body)

    var data Func
    err := decoder.Decode(&data)
    if err != nil {
        panic(err)
    }

    Name := data.Name
    Status := data.Status

    database, err := db.CreateDatabase()
    if err != nil {
        log.Fatal("Not connect to db")
    }
    _, err = database.Exec("INSERT INTO `func` (Data, Name) VALUES ($1, $2)", Name, Status)
    if err != nil {
        log.Fatal("Error inserting data")
    }

    log.Println("Alright!")
    w.WriteHeader(http.StatusOK)
}

So i make one go build and after i make a ./nameproject

So, i go in the PostMan and make a post http request passing the Name and Status in form-data but i receive:

2019/07/12 22:20:38 http: panic serving [::1]:54600: invalid character '-' in numeric literal

Tags : go


Related Questions