'Post API getting invalid character '-' in numeric literal

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` (Name, Status) 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

go


Solution 1:[1]

I experience the same issue while using form data in postman,I finally resolved to using json and it worked

Solution 2:[2]

You should change form-data to raw->JSON and send like this:

{
    "Name" : "morefeizi",
    "Status" : "1"
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Slycreator
Solution 2 Tyler2P