iterate in an array of type struct

All identifiers defined in a package are private to that package if its name starts with a lowercase letter. This is called unexported. This rule applies to struct fields as well.

You must export identifiers if you want to refer to them from other packages. So simply start their names with an uppercased letter:

type DirStruct struct {
    DirName      string
    DirPath      string
    FoldersCount int
    FilesCount   int
}

Spec: Exported identifiers:

An identifier may be exported to permit access to it from another package. An identifier is exported if both:

  1. the first character of the identifier’s name is a Unicode upper case letter (Unicode class “Lu”); and
  2. the identifier is declared in the package block or it is a field name or method name.

All other identifiers are not exported.

If you’re new to the language, please take the Go Tour first. This is covered in the Basics: Exported names.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top