我正在研究 Golang,GORM 以使用 Echo 框架实现 API


我正在使用以下结构和函数来生成 JSON


type User struct {

    gorm.Model

    Name     string `json:"name"`

    Username string `json:"username"`

    Password string 

}


func GetUsers(c echo.Context) error {

    db := db.GetDBInstance()

    users := []model.User{}

    db.Find(&users)

    return c.JSON(http.StatusOK, users)

}

这是我的 JSON 响应


[

 {

  ID: 1,

  CreatedAt: "2020-04-21T05:28:53.34966Z",

  UpdatedAt: "0001-01-01T00:00:00Z",

  DeletedAt: null,

  name: "",

  username: "test",

  Password: "test123"

 }

]

我想将其转换为以下 JSON


{

  data: [{

   ID: 1,

   CreatedAt: "2020-04-21T05:28:53.34966Z",

   UpdatedAt: "0001-01-01T00:00:00Z",

   DeletedAt: null,

   name: "",

   username: "test",

   Password: "test123"

  }]

}

任何帮助将不胜感激