N
N
Newmo2019-10-17 14:45:01
go
Newmo, 2019-10-17 14:45:01

How to parse the structure?

There is a structure in the db package. Using the Read() method, I write data to it (link1 and link2):

type Images struct {
  Original string
  Crop     string
}

I receive it:
images := db.Read()
Вывожу и получаю:
&[{link1 link2}]

How can I display each element separately from the structure?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav, 2019-10-17
@Newmo

Judging by the output, you have an array

images := db.Read()
for _, img := range images {
    fmt.Println(img.Original)
    fmt.Println(img.Crop)
}

Also, judging by the output, not []Images is returned, but *[]Images (for some reason)
there will be a different code for this
images := db.Read()
for _, img := range *images {
    fmt.Println(img.Original)
    fmt.Println(img.Crop)
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question