I have this code
files, _ := ioutil.ReadDir("public/my-template/imagesT/gallery/")
for _, f:=range files {
fmt.Println(f.Name())
}
How can return an array contain all f.Name
to use them in index.html ?
Create a slice and use append
to add the file names in your loop.
var fileNames []string
files, _ := ioutil.ReadDir("public/my-template/imagesT/gallery/")
for _, f := range files {
fileNames = append(fileNames, f.Name())
}
// Now fileNames contains all of the file names for you to pass to your template.
Also note that you should not ignore the possible error returned on the line
files, _ := ioutil.ReadDir("public/my-template/imagesT/gallery/")