My goal is to get some filtered records from database. Filtration is based on a struct which depends on another struct:
type Group struct {
ID primitive.ObjectID
Name string
}
type Role struct {
ID primitive.ObjectID
Name string
Description string
Groups []*group.Group
}
I create an object of Role struct from URL query parameters:
var roleWP Role
if r.URL.Query().Has("name") {
name := r.URL.Query().Get("name")
roleWP.Name = name
}
if r.URL.Query().Has("description") {
description := r.URL.Query().Get("description")
roleWP.Description = description
}
if r.URL.Query().Has("groups") {
//How would look groups parameter?
}
Filling name
and description
fields of Role
struct is pretty simple. The whole url would be:
myhost/roles?name=rolename&description=roledescription
But how would look url if I want to pass data for Group
struct? Is it possible to pass data as a json object in query parameter? Also, I want to mention that groups
field in Role
is an array. My ideal dummy url would look like: myhost/roles?name=rolename&description=roledescription&groups={name:groupname1}&groups={name:groupname2}