Hi!,
Still struggling with some things since I’m new to go but pretty much excited because things are starting to work…
I’m working with some nested structs that cotain time.Time
fields.
I want to marshal those structs as JSON to save them to a file, but I need to convert those time.Time
fields as string
because I don’t want the long date format that golang uses.
Therefore I need to convert those fields using time.Format("2006-01-02")
and then marshal the struct.
This is my nested struct
type Flujo struct {
Date time.Time
Rate float64
Amort float64
Residual float64
Amount float64
}
type Bond struct {
ID string
Ticker string
IssueDate time.Time
Maturity time.Time
Coupon float64
Cashflow []Flujo
}
Do I need to convert the struct to the type below, and then marshal it with json.Marshal
?
type FlujoOut struct {
Date string
Rate float64
Amort float64
Residual float64
Amount float64
}
type BondOut struct {
ID string
Ticker string
IssueDate string
Maturity string
Coupon float64
Cashflow []FlujoOut
}
If true, how do I convert one struct to another considering it has a nested slice of struct inside?
Thanks in advance!!