-3

I have generated go struct from json. And it gave me next output:

type PartnerBody87 struct {
    Imp []struct {
        Bidfloor float64 `json:"bidfloor"`
        Secure   int     `json:"secure"`
        Ext      struct {
            Type    string `json:"type"`
            Webpush int    `json:"webpush"`
        } `json:"ext"`
        ID    string `json:"id"`
        Tagid string `json:"tagid"`
    } `json:"imp"`
}

I tried different ways, and cannot find proper one of how to initiate the value for Imp []struct.

Update: I know that I can split struct into few types. But I'm curious if Go have ability to set everything in 1 struct - than how to use it?

Bohdan Srdi
  • 144
  • 1
  • 6

1 Answers1

-1

You can split them like this:


type PartnerBody87 struct {
    Imp []Imp `json:"imp"`
}

type Imp struct {
    Bidfloor float64 `json:"bidfloor"`
    Secure   int     `json:"secure"`
    Ext      Ext     `json:"ext"`
    ID       string  `json:"id"`
    Tagid    string  `json:"tagid"`
}
type Ext struct {
    Type    string `json:"type"`
    Webpush int    `json:"webpush"`
}