在Golang结构中分配DB列

I have two tables like Retailers and products in database. Retailer has many Products.

They following are the structs I have defined in golang.

type Retailers struct {
  Id int 
  Name string
  Products []Product
}

type Product struct {
  Id int 
  Description string
  Url string 
}

The following is the query am using to fetch data from Database.

select r.id, r.name, p.id, p.description, p.url from retailers r JOIN products on r.id = r.retailer_id

Using the above struct and query I wish to form the json as below

{
    "id": "DFT",
    "name": "Amazon",
    "products":[
        {
            "id":"APP0001",
            "description":"Iphone5s",
            "url":"www.Iphone5s.com"
        },
        {
            "id":"APP0002",
            "description":"Iphone6s",
            "url":"www.Iphone6s.com"
        }
    ]
}

How can I achieve this using golang?

You need to specify struct tags in your struct definition:

type Retailers struct {
  Id int `json:"id"`
  Name string `json:"name"`
  Products []Product `json:"products"`
}

type Product struct {
  Id int `json:"id"`
  Description string `json:"description"`
  Url string `json:"url"`
}