Functions are at the core of the language. They provide a mechanism to group and organize our code to separate and distinct pieces of functionality. They can be used to provide an API to the packages we write and are a core component to concurrency.
- Functions can return multiple values and most return an error value.
- The error value should always be checked as part of the programming logic.
- The blank identifier can be used to ignore return values.
https://golang.org/doc/effective_go.html#functions
http://www.goinggo.net/2013/10/functions-and-naked-returns-in-go.html
http://www.goinggo.net/2013/06/understanding-defer-panic-and-recover.html
Return multiple values (Go Playground)
Blank identifier (Go Playground)
Redeclarations (Go Playground)
Anonymous Functions/Closures (Go Playground)
Recover panics (Go Playground)
Part A Declare a struct type to maintain information about a user. Declare a function that creates value of and returns pointers of this type and an error value. Call this function from main and display the value.
Part B Make a second call to your function but this time ignore the value and just test the error value.
Template (Go Playground) | Answer (Go Playground)
All material is licensed under the Apache License Version 2.0, January 2004.