summaryrefslogtreecommitdiffhomepage
path: root/go.html.markdown
diff options
context:
space:
mode:
authorQuint Guvernator <quintus.public@gmail.com>2014-02-02 15:11:15 -0500
committerQuint Guvernator <quintus.public@gmail.com>2014-02-02 15:11:15 -0500
commitded11e254f75edfd83fc816fe609431e182f5155 (patch)
tree2951d9af66bf27304dedb3ade8c5378ae8ee4e64 /go.html.markdown
parent8d82b5594749c52b5b8fa3b988ae65098a47ab1c (diff)
added defer example
decided not to use file i/o as an example because external file access is rare in other tutorials.
Diffstat (limited to 'go.html.markdown')
-rw-r--r--go.html.markdown13
1 files changed, 13 insertions, 0 deletions
diff --git a/go.html.markdown b/go.html.markdown
index d1a0ae34..a66e8c4b 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -7,6 +7,7 @@ contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
- ["Christopher Bess", "https://github.com/cbess"]
- ["Jesse Johnson", "https://github.com/holocronweaver"]
+ - ["Quint Guvernator", "https://github.com/qguv"]
---
Go was created out of the need to get work done. It's not the latest trend
@@ -180,9 +181,21 @@ func learnFlowControl() {
goto love
love:
+ learnDefer() // A quick detour to an important keyword.
learnInterfaces() // Good stuff coming up!
}
+
+
+func learnDefer() (ok bool) {
+ // deferred statements are executed just before the function returns.
+ defer fmt.Println("deferred statements execute in reverse (LIFO) order.")
+ defer fmt.Println("\nThis line is being printed first because")
+ // defer is commonly used to close a file, so the function closing the file
+ // stays close to the function opening the file
+ return true
+}
+
// Define Stringer as an interface type with one method, String.
type Stringer interface {
String() string