You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EN/struct/struct.md
+32-1Lines changed: 32 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,4 +26,35 @@ This also confirms that many answers often go back to the roots of computer data
26
26
27
27
For struct types, the order of the fields is critical. If two struct types contain exactly the same fields, but in a different order or are partially merged, then the two structs are different types!
28
28
29
-
If the struct field starts with a capital letter, then the field is exported (visible outside the package), which also conforms to the visibility rules of the Go language. So a struct can contain both exported and unexported variables.
29
+
If the struct field starts with a capital letter, then the field is exported (visible outside the package), which also conforms to the visibility rules of the Go language. So a struct can contain both exported and unexported variables.
30
+
31
+
32
+
### struct{} empty structure
33
+
34
+
* struct{} features
35
+
struct{} is an element free structure type, which is usually used when there is no information storage. The advantage is that the size is 0 and no memory is needed to store values of type struct{}.
36
+
* The difference between struct{} and struct{}{}
37
+
Struct{}{} is a literal, which constructs a struct{} type value, which is also null.
38
+
* Declare as map[string]struct{}
39
+
Since struct{} is empty and does not care about the content, the map is transformed into set
40
+
Map can obtain whether the key exists through the "comma OK" mechanism, for example_ , OK: = map ["key"], if there is no corresponding value, OK is false.
0 commit comments