diff --git a/00-notes.txt b/00-notes.txt index e1bd62c..3d28281 100644 --- a/00-notes.txt +++ b/00-notes.txt @@ -29,3 +29,4 @@ * deploying to heroku * sort-by * errors + * compilation diff --git a/xx-exit b/xx-exit deleted file mode 100755 index c3f482c..0000000 Binary files a/xx-exit and /dev/null differ diff --git a/xx-file-open.go b/xx-file-open.go new file mode 100644 index 0000000..7dc5739 --- /dev/null +++ b/xx-file-open.go @@ -0,0 +1,18 @@ +package main + +import ("fmt"; "os") + +func main() { + file, err := os.Open("xx-file-open.go") + if err != nil { + panic(err) + } + defer file.Close() + + stat, err := file.Stat() + if err != nil { + panic(err) + } + + fmt.Println("Program has", stat.Size(), "bytes") +} diff --git a/xx-file-read.go b/xx-file-read.go new file mode 100644 index 0000000..ef5369d --- /dev/null +++ b/xx-file-read.go @@ -0,0 +1,11 @@ +package main + +import ("fmt"; "io/ioutil") + +func main() { + contents, err := ioutil.ReadFile("xx-file-read.go") + if err != nil { + return + } + fmt.Print(string(contents)) +} diff --git a/xx-file-write.go b/xx-file-write.go new file mode 100644 index 0000000..8dd64df --- /dev/null +++ b/xx-file-write.go @@ -0,0 +1,12 @@ +package main + +import "os" + +func main() { + file, err := os.Create("xx-file-write.txt") + if err != nil { + panic(err) + } + defer file.Close() + file.WriteString("contents\n") +} diff --git a/xx-sort.go b/xx-sort.go new file mode 100644 index 0000000..b5c2324 --- /dev/null +++ b/xx-sort.go @@ -0,0 +1,12 @@ +package main + +import ("fmt"; "sort") + +func main() { + strs := []string{"foo", "bar", "bat"} + fmt.Println(strs) + fmt.Println() + + sort.Strings(strs) + fmt.Println(strs) +}