Gin: How can I bind from form-data with array objects ?

Created on 31 Aug 2018  路  7Comments  路  Source: gin-gonic/gin

I have form-data like send by using postman. But I don't know how to create struct to bind that data
screenshot from 2018-08-31 16-38-01

Anyone can have me please!

Most helpful comment

I think this should be supported because HTML forms without JS cannot send any JSON encoded forms. Furthermore if a file field is included in the form, multipart form encoding is the only possible option.

All 7 comments

please see QueryArray and PostFormArray

using JSON post will be better.
a lot form type support not well

This is my struct

type BusinessPayloadRequest struct {
    Location struct {
        Latitude  float64 `form:"latitude" bson:"latitude"`
        Longitude float64 `form:"longitude" bson:"longitude"`
    } `form:"location" bson:"-"`
    AddressComponents []AddressComponents `form:"addressComponents[]" bson:"addressComponents"`
    WorkingHours      []WorkingHour       `form:"workingHours" bson:"workingHours"`

}

type WorkingHour struct {
    OpenHour    int `form:"openHour" bson:"openHour"`
    OpenMinute  int `form:"openMinute" bson:"openMinute"`
    CloseHour   int `form:"closeHour" bson:"closeHour"`
    CloseMinute int `form:"closeMinute" bson:"closeMinute"`
}

How use c.Bind but seem doesn't working

Bind does not support these type, you need post json data.
Bind form only support a basic type, like string, int..etc

Yes, I think like you. Ok I'll use content type application/json

I think this should be supported because HTML forms without JS cannot send any JSON encoded forms. Furthermore if a file field is included in the form, multipart form encoding is the only possible option.

please fix this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rawoke083 picture rawoke083  路  3Comments

mdnight picture mdnight  路  3Comments

sofish picture sofish  路  3Comments

iiinsomnia picture iiinsomnia  路  3Comments

kekemuyu picture kekemuyu  路  3Comments