Err: cannot use *{...} (type *) as type * in slice literal

Hello Community.
My first time posting and writing for golang.
I am making a Golang struct.
The struct types are correct, but the struct initialization gives me errors.
I am using struct inside struct multiple times.
The link to Go Playground with the Example

Errros shown: ./prog.go:45:4: undefined: Amount ./prog.go:45:4: cannot use TheAmount{...} (type TheAmount) as type PurchaseUnits in slice literal
I got the same errors for every field, how could i solve this?
Thanks Friends!

The Purchase_units field’s type is []PurchaseUnits But you’re putting fields in there like Address, etc., as if it were a single PurchaseUnits struct. If you want a slice of PurchaseUnits, then add a second set of { and } inside of your []PurchaseUnits on line 44.

Also, you should not use floating point numbers when dealing with currency.

Thanks for the reply.
It is working now.
What should i use for currency? int or?

In Go, I would recommend storing cents as one of the integer data types (int64, int32, int, etc.).

1 Like