Revel+mgo golang - 如何定义结构类型来处理来自数据库的嵌套 objects?

Revel+mgo golang - How to define a struct type to handle nested objects coming from the db?

我的 mongo collection -

中有此类文档
{
    "_id" : "3wPEpWwECbrTrnSbh",
    "brandId" : 45,
    "title" : "brandtitle",
    "logoImg" : "brandtitle.png",
    "category" : {
        "category 1" : [ 
            {
                "cat" : "A1 Plus Champ"
            }, 
            {
                "cat" : "A108"
            }, 
            {
                "cat" : "A6"
            },            
        ],
        "category 2" : [ 
            {
                "cat" : "something"
            }, 
            {
                "cat" : "soemthing else"
            }, 
            {
                "cat" : "something else"
            },            
        ],
    },
    "isActive" : true,
    "isOnboarded" : false,
    "serviceNumber" : 18605001492.0
}

所以有几个品牌。 我可以得到所有东西,除了这个类别。

我的模型代码数据类型是 -

type Brand struct {
    Id string           `bson:"_id" json:"_id"`
    Brandid int         `bson:"brandId" json:"brandId"`
    Title string        `json:"title"`
    Logoimg string      `bson:"logoImg" json:"logoImg"`
    Category []string   `bson:"category" json:"category"`
    Isactive bool       `bson:"isActive" json:"isActive"`
    Isonboarded bool    `bson:"isOnboarded" json:"isOnboarded"`
    Servicenumber int   `bson:"serviceNumber" json:"serviceNumber"`
}

我现在将 Category 当作一个字符串数组,但这当然是错误的。

输出看起来像这样 -

  {
    "_id": "3wPEpWwECbrTrnSbh",
    "brandId": 45,
    "title": "brandtitle",
    "logoImg": "brandtitle.png",
    "category": null,
    "isActive": true,
    "isOnboarded": false,
    "serviceNumber": 18605001492
  }

我应该如何构建此结构才能显示我从数据库中获取的数据类型?

type Brand struct {
    Id string           `bson:"_id" json:"_id"`
    Brandid int         `bson:"brandId" json:"brandId"`
    Title string        `json:"title"`
    Logoimg string      `bson:"logoImg" json:"logoImg"`
    Category      map[string][]map[string]string   `bson:"category" json:"category"`
    Isactive bool       `bson:"isActive" json:"isActive"`
    Isonboarded bool    `bson:"isOnboarded" json:"isOnboarded"`
    Servicenumber int   `bson:"serviceNumber" json:"serviceNumber"`
}