I have two structs named as "Invoices", "Transactions". These are GORM models. I wanna merge these structs and convert json.
Example:
type Invoice struct {
gorm.Model
DocType string `json:"docType"`
Total float64 `json:"total"`
}
type Transaction struct {
gorm.Model
DocType string `json:"docType"`
Total float64 `json:"total"`
Account uint `json:"account"`
}
I wanna response like;
[
{docType:"invoice", total: "123.00"}
{docType:"transaction", account:"1", total: "124.00"}
{docType:"invoice", total: "125.00"}
]
x:=[]interface{}{invoice,transaction,invoice,transaction}, json.Marshal(x)x:=[]interface{}{[]invoice,[]transaction}, json.Marshal(x)[]interface{}{inv,tr}whereinvandtrare structs you retrieved from the db.