#Read Struct values with sub struct pointers

5 messages · Page 1 of 1 (latest)

stone stag
#

Hello guys I'm new to go and I was trying to access the values of my data struct. But it keeps giving me the memory address unless I specify which field I wanna access. How can I overcome it?

var data struct {
    company *entities.Company
    stores  []*entities.Store
}

data.company = company
data.stores = stores

fmt.Println(data) // Gives memory address of my structs 
fmt.Println(data.company) // ID: "1" Name: "Foo" (Works as I want) 

err = response.JSON(w, http.StatusOK, data) // sends empty json
limpid echo
#

You need to export your fields if you want to use them with JSON

stone stag
#

can you please give an example with the current struct i gave

limpid echo
stone stag
#

thank you so much !