more
This commit is contained in:
parent
43bbea1d76
commit
7553dfa25a
@ -29,3 +29,4 @@
|
|||||||
* deploying to heroku
|
* deploying to heroku
|
||||||
* sort-by
|
* sort-by
|
||||||
* errors
|
* errors
|
||||||
|
* compilation
|
||||||
|
18
xx-file-open.go
Normal file
18
xx-file-open.go
Normal 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
11
xx-file-read.go
Normal 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
12
xx-file-write.go
Normal 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
12
xx-sort.go
Normal 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user