Go supports structs (short for structures) that allow programmers to define user-defined types. Related data that exhibits a “has-a” relationship can be grouped into a single logical unit using structs. Methods in Go are functions that can be tied to user-defined types to define their behavior. Another important feature of the Go language is the concept of interfaces. In Go, structs and interfaces go hand in hand to organize methods and data handling. ...
5. Structs, Methods, and Interfaces
Get Beginning Go Programming: Build Reliable and Efficient Applications with Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.