more
This commit is contained in:
parent
7854ae3cdf
commit
43bbea1d76
@ -22,3 +22,10 @@
|
||||
* stack overflow questions
|
||||
* handbook format
|
||||
* rosetta stone
|
||||
* building an actual fucking app
|
||||
* versioned transitive libraries and pegging
|
||||
* creating and distributing packages, putting on github
|
||||
* distributing go binary programs
|
||||
* deploying to heroku
|
||||
* sort-by
|
||||
* errors
|
||||
|
16
11b-case.go
Normal file
16
11b-case.go
Normal file
@ -0,0 +1,16 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
i := 3
|
||||
switch i {
|
||||
case 0: fmt.Println("Zero")
|
||||
case 1: fmt.Println("One")
|
||||
case 2: fmt.Println("Two")
|
||||
case 3: fmt.Println("Three")
|
||||
case 4: fmt.Println("Four")
|
||||
case 5: fmt.Println("Five")
|
||||
default: fmt.Println("Unknown Number")
|
||||
}
|
||||
}
|
31
42-select.go
Normal file
31
42-select.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import ("fmt"; "time")
|
||||
|
||||
func main() {
|
||||
c1 := make(chan string)
|
||||
c2 := make(chan string)
|
||||
d := make(chan bool, 1)
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 1500)
|
||||
c1 <- "from 1"
|
||||
}()
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 2000)
|
||||
c2 <- "from 2"
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for i :=0; i < 2; i ++ {
|
||||
select {
|
||||
case msg1 := <- c1:
|
||||
fmt.Println(msg1)
|
||||
case msg2 := <- c2:
|
||||
fmt.Println(msg2)
|
||||
}
|
||||
}
|
||||
d <- true
|
||||
}()
|
||||
<- d
|
||||
}
|
24
43-timeout.go
Normal file
24
43-timeout.go
Normal file
@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import ("fmt"; "time")
|
||||
|
||||
func main() {
|
||||
c := make(chan string)
|
||||
d := make(chan bool, 1)
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Millisecond * 1500)
|
||||
c <- "ready"
|
||||
}()
|
||||
|
||||
go func() {
|
||||
select {
|
||||
case msg := <- c:
|
||||
fmt.Println(msg)
|
||||
case <- time.After(time.Millisecond * 1000):
|
||||
fmt.Println("timeout")
|
||||
}
|
||||
d <- true
|
||||
}()
|
||||
<- d
|
||||
}
|
21
44-strings.go
Normal file
21
44-strings.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import ("fmt"; "strings")
|
||||
|
||||
func p(o interface{}) {
|
||||
fmt.Println(o)
|
||||
}
|
||||
|
||||
func main() {
|
||||
p(strings.Contains("test", "es"))
|
||||
p(strings.Count("test", "t"))
|
||||
p(strings.HasPrefix("test", "te"))
|
||||
p(strings.HasSuffix("test", "st"))
|
||||
p(strings.Index("test", "e"))
|
||||
p(strings.Join([]string{"a","b"}, "-"))
|
||||
p(strings.Repeat("a", 5))
|
||||
p(strings.Replace("aaaa", "a", "b", 2))
|
||||
p(strings.Split("a-b-c-d-e", "-"))
|
||||
p(strings.ToLower("TEST"))
|
||||
p(strings.ToUpper("test"))
|
||||
}
|
10
45-bytes.go
Normal file
10
45-bytes.go
Normal file
@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
arr := []byte("some bytes")
|
||||
str := string([]byte{'a', ' ', 's', 't', 'r', 'i', 'n', 'g'})
|
||||
fmt.Println(arr)
|
||||
fmt.Println(str)
|
||||
}
|
14
xx-exit.go
Normal file
14
xx-exit.go
Normal file
@ -0,0 +1,14 @@
|
||||
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
|
Loading…
x
Reference in New Issue
Block a user