Hello, You can use a map, map[string][]Data.
Please check the sample code below: https://play.golang.org/p/7JmtoMag86J Best regards... On Sunday, July 12, 2020 at 9:21:43 AM UTC+3, tien...@gmail.com wrote: > > I have function as below > > I have function as below > > func Get DataById(w http.ResponseWriter, r *http.Request) { > uid := "11111" > data := models.GetTransport(uid) > > w.WriteHeader(http.StatusOK) //200 > if data == nil { > resp := u.Message(false, "Can not found") > u.Respond(w, resp) > } else { > resp := u.Message(true, "success") > resp["data"] = data > u.Respond(w, resp) > } > } > > > End it was response data > > { > "data": [ > { > "day": 1, > "begin": "AAAA", > }, > { > "day": 1, > "begin": "BBBB", > }, > { > "day": 2, > "begin": "CCCC", > }, > { > "day": 2, > "begin": "DDDD", > }, > ] > } > > But I want group by Day and output json as below > > > { > "data": [ > "day1:" [ > { > "begin": "AAAA", > }, > { > "begin": "BBBB", > }, > ] > "day2:" [ > { > "begin": "CCCC", > }, > { > "begin": "DDDD", > }, > ] > ] > } > > > *How can I do it, please give me advice.Thanks a lot* > > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/deaa94db-8a00-4172-95da-47f51cffa5d6o%40googlegroups.com.