Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72473

Binding array of object from html with gin-gonic

$
0
0

There is possibility to bind array of values from html page in array using gin-gonic.

<form method="POST" action="mygo">
 <input type=hidden name="emails" value="email1@email.com">
 <input type=hidden name="emails" value="email2@email.com">
 <input type=hidden name="emails" value="email3@email.com">
</form>

can be parsed using

func Handler( c *gin.Context) {
    emails:= c.PostFormArray("emails")
}

Is it the way to bind array of objects from html page ? Something like this

<form method="POST" action="mygo">
 <input name="users[0].name" value="John"> <input name="users[0].email" value="john@email.com">
 <input name="users[1].name" value="Jack"> <input name="users[1].email" value="jack@email.com">
</form>

to bind in something like this

type User struct {
    Name string
    Email string
}
type Users struct {
    Users []User
}

func Handler( c *gin.Context) {
    users:=Users{}
    c.Bind(&users)
    log.Println(users.Users[0]) // John john@email.com 
}

Viewing all articles
Browse latest Browse all 72473

Trending Articles