From ba78f8b327493da43075dc00c946099990ef3f68 Mon Sep 17 00:00:00 2001 From: Mark McGranaghan Date: Wed, 3 Oct 2012 09:55:25 -0700 Subject: [PATCH] exit work --- src/028-interfaces/interfaces.go | 2 ++ src/073-exit/.gitignore | 1 + src/073-exit/exit.go | 18 +++++++++++++----- src/073-exit/exit.sh | 2 ++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/073-exit/.gitignore diff --git a/src/028-interfaces/interfaces.go b/src/028-interfaces/interfaces.go index 590b986..3702d28 100644 --- a/src/028-interfaces/interfaces.go +++ b/src/028-interfaces/interfaces.go @@ -7,3 +7,5 @@ import "fmt" type Shape interface { area() float64 } + +// todo: that great blog post on interfaces diff --git a/src/073-exit/.gitignore b/src/073-exit/.gitignore new file mode 100644 index 0000000..a3abe50 --- /dev/null +++ b/src/073-exit/.gitignore @@ -0,0 +1 @@ +exit diff --git a/src/073-exit/exit.go b/src/073-exit/exit.go index ad4c531..19e070d 100644 --- a/src/073-exit/exit.go +++ b/src/073-exit/exit.go @@ -1,16 +1,24 @@ -// Exit - -package main +// ## Exit // Use `os.Exit` to immediatly exit with a given // status. + +package main + import "os" func main() { - // This `println` will never be reached because the - // exit is immediate. + // `defer`s will _not_ be run when using `os.Exit`, so + // this `println` will never be called. defer println("!") + + // Exit with status 3. os.Exit(3) } +// Note that unlike e.g. C, Go does not use an integer +// return value from `main` to indicate exit status. If +// you'd like to exit with a non-zero status you should +// use `os.Exit`. + // todo: discuss building before getting here diff --git a/src/073-exit/exit.sh b/src/073-exit/exit.sh index c3539ba..6418d11 100644 --- a/src/073-exit/exit.sh +++ b/src/073-exit/exit.sh @@ -9,3 +9,5 @@ $ go build exit.go $ ./exit $ echo $? 3 + +# Note that the `!` from our program never got printed.