02-struct_types/

directory
v0.0.0-...-35bbffe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2015 License: Apache-2.0

README

Struct Types - Language Syntax

Struct types are a way of creating complex types that group fields of data together. They are a great way of organizing and sharing the different aspects of the data your program consumes.

Notes

  • We can use the struct literal form to initialize a value from a struct type.
  • The dot (.) operator allows us to access individual field values.
  • We can create anonymous structs.

http://www.goinggo.net/2013/07/understanding-type-in-go.html

http://www.goinggo.net/2013/07/object-oriented-programming-in-go.html

Code Review

Declare, create and initialize struct types (Go Playground)

Anonymous struct types (Go Playground)

Advanced Code Review

Struct type alignments (Go Playground)

Exercises

Exercise 1

Part A: Declare a struct type to maintain information about a user (name, email and age). Create a value of this type, initialize with values and display each field.

Part B: Declare and initialize an anonymous struct type with the same three fields. Display the value.

Template (Go Playground) | Answer (Go Playground)


Ardan Labs Ardan Studios GoingGo Blog


All material is licensed under the Apache License Version 2.0, January 2004.

Directories

Path Synopsis
advanced
example1
Sample program to show how struct types align on boundaries.
Sample program to show how struct types align on boundaries.
Sample program to show how to declare and initialize struct types.
Sample program to show how to declare and initialize struct types.
Sample program to show how to declare and initialize anonymous struct types.
Sample program to show how to declare and initialize anonymous struct types.
exercises
exercise1
Declare a struct type to maintain information about a user (name, email and age).
Declare a struct type to maintain information about a user (name, email and age).
template1
Declare a struct type to maintain information about a user (name, email and age).
Declare a struct type to maintain information about a user (name, email and age).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL