func main() {
fmt.Println("Enter main")
defer func() {
if e := recover(); e != nil {
fmt.Printf("Fatal error: %s\n", e)
}
}()
outerFunc()
fmt.Println("Quit main")
}
fmt.Println("Enter main")
defer func() {
if e := recover(); e != nil {
fmt.Printf("Fatal error: %s\n", e)
}
}()
outerFunc()
fmt.Println("Quit main")
}
2018-09-06
func main() {
ch4 := make(chan int, 1)
for i := 0; i < 4; i++ {
select {
case e, ok := <-ch4:
if !ok {
fmt.Println("End.")
return
}
fmt.Println(e)
close(ch4)
default:
fmt.Println("No Data!")
ch4 <- 1
}
}
}
ch4 := make(chan int, 1)
for i := 0; i < 4; i++ {
select {
case e, ok := <-ch4:
if !ok {
fmt.Println("End.")
return
}
fmt.Println(e)
close(ch4)
default:
fmt.Println("No Data!")
ch4 <- 1
}
}
}
2018-09-05
func main() {
map1 := map[int]string{1: "Golang", 2: "Java", 3: "Python", 4: "C"}
for i, s := range map1 {
fmt.Printf("%d: %s\n", i, s)
}
}
map1 := map[int]string{1: "Golang", 2: "Java", 3: "Python", 4: "C"}
for i, s := range map1 {
fmt.Printf("%d: %s\n", i, s)
}
}
2018-09-05
func main() {
ia := []interface{}{byte(6), 'a', uint(10), int32(-4)}
switch v := ia[rand.Intn(4)%2 + 1]; interface{}(v).(type) {
case string, uint, int32 :
fmt.Printf("Case A.")
case byte :
fmt.Printf("Case B.")
default:
fmt.Println("Unknown!")
}
}
ia := []interface{}{byte(6), 'a', uint(10), int32(-4)}
switch v := ia[rand.Intn(4)%2 + 1]; interface{}(v).(type) {
case string, uint, int32 :
fmt.Printf("Case A.")
case byte :
fmt.Printf("Case B.")
default:
fmt.Println("Unknown!")
}
}
2018-09-05