This commit is contained in:
Mark McGranaghan 2012-09-21 07:54:20 -07:00
parent 23dba0980b
commit 354a9d862f
72 changed files with 36 additions and 17 deletions

21
054-exit.go Normal file
View File

@ -0,0 +1,21 @@
package main // Use `os.Exit` to immediatly exit with a given
// status.
import "os"
func main() {
defer println("!") // This `println` will never be reached.
os.Exit(3)
}
/*
$ go run exit.go // If you run `exit.go` using `go run`, the exit
exit status 3 // will be picked up by `go` and printed.
$ go build exit.go // By building and executing a binary you can see
$ ./exit // the status in the terminal
$ echo $?
3
*/
// == todo
// discuss building before getting here

View File

@ -1,14 +0,0 @@
package main
import "os"
func main() {
os.Exit(3)
}
// $ go run xx-exit.go
// exit status 3
// $ go build xx-exit.go
// $ ./xx-exit
// $ echo $?
// 3

View File

@ -24,7 +24,6 @@ recursion
defer
panic
recover
values
pointers
new
structs
@ -52,7 +51,7 @@ env
epoch
errors
exec
exits
exit
file-open
file-read
file-write

View File

@ -9,8 +9,16 @@ import (
"strings"
"regexp"
"os"
"sort"
)
func minInt(a, b int) int {
if (a < b) {
return a
}
return b
}
func main() {
// read names of source files
sourceNames := make([]string, 0)
@ -33,7 +41,12 @@ func main() {
// sanity check two lists
if len(sourceNames) != len(indexNames) {
panic("mismatched names")
sort.Strings(sourceNames)
sort.Strings(indexNames)
for i := 0; i < minInt(len(sourceNames), len(indexNames)); i++ {
fmt.Printf("%s %s\n", sourceNames[i], indexNames[i])
}
os.Exit(1)
}
// rename some stuff