Structs
suggest changeA struct groups related variables into a single entity.
Additionally, structs can have methods, similar to classes in C++ or Java.
Unlike classes in C++ or Java, structs don’t implement inheritance. You can achieve some of the code re-use with struct embedding.
Zero value of a struct is a struct whose fields are set to their respective zero values.
Basics of structs:
main.go
type MyStruct struct {
IntVal int
StringVal string
unexportedIntVal int
}
Exported vs. unexported fields (private vs public)
Duplicate a struct (make a copy)
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents