go 坑

数组错误版本:

package main

import (
    "fmt"
)

var c chan string

func Pingpong(s []int) {
    s = append(s, 3)

}

func main() {
    s := make([]int, 0)
    fmt.Println(s)
    Pingpong(s)
    fmt.Println(s)
}

数组推荐版本:

package main

import (
    "fmt"
)

var c chan string

func Pingpong(s []int) []int {
    s = append(s, 3)
    return s
}

func main() {
    s := make([]int, 0)
    fmt.Println(s)
    s = Pingpong(s)
    fmt.Println(s)
}

time 坑:

package main

import (
    "fmt"
    "time"
)

func main() {
    t := time.Now()
    fmt.Println(t)

    fmt.Println(t.Format(time.ANSIC))
    fmt.Println(t.Format("Mon Jan _2 15:04:05 2006"))
    //自定义时间---巨坑
    fmt.Println(t.Format("Fri Nov 17 15:27:00 2017"))
}

range 与闭包的坑:

package main

import (
	"fmt"
)

func main() {
	s := []string{"a", "b", "c"}
	for _, v := range s {
		go func(v string) {
			fmt.Println(v)
		}(v) // 这里需要传递参数
	}
	select {}//这里报错,故意做的死锁,不用管
}