This is a creation in Article, where the information may have evolved or changed.
- The way to provide outside access in the go language or the structure must be capitalized in the first letter
A struct is defined in a common header file, as follows:
Type Header struct { ver int magic_num int len int}
In another execution file, initialization and assignment are made:
VAR head comm. Header; Head.ver = 1 head.magic_num = 0xffee head.len = 0
Compile times wrong
./example_struct2binary.go:21:head.ver undefined (cannot refer to unexported field or method ver)
./example_struct2binary.go:22:head.magic_num undefined (cannot refer to unexported field or method Magic_num)
./example_struct2binary.go:23:head.len undefined (cannot refer to unexported field or method Len)
Later, it was recalled that the way to provide outside access in the go language or structure must be capitalized. This struct is capitalized only on the struct name, and the field in it is not capitalized, and the go language should be considered to be two different processes when the template is called, so the value cannot be found. The first letter of the field in the structure is changed to uppercase and then resolved.