This commit is contained in:
Mark McGranaghan 2012-09-16 17:57:09 -07:00
parent 43bbea1d76
commit 7553dfa25a
6 changed files with 54 additions and 0 deletions

View File

@ -29,3 +29,4 @@
* deploying to heroku
* sort-by
* errors
* compilation

BIN
xx-exit

Binary file not shown.

18
xx-file-open.go Normal file
View File

@ -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")
}

11
xx-file-read.go Normal file
View File

@ -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))
}

12
xx-file-write.go Normal file
View File

@ -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")
}

12
xx-sort.go Normal file
View File

@ -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)
}