golang 3个点 3dots

golang 3个点的 4个用处

1. 定义 可变长参数 的函数/方法

func Test(strSlice ...string) {
    for i, s := range strSlice {
        log.Println(i, s)
    }
}

在函数内部,strSlice是一个 []string 类型

2. 向变长参数的函数穿参

strSlice := []string{"a", "b", "c"}
Test(strSlice...)

Test函数只能接收 多个string类型的参数

var intSlice []int
appendSlice := []int{1, 2, 3}
intSlice = append(intSlice, appendSlice...)

append可以把string打散成byte

var byteSlice []byte
byteSlice = append(byteSlice, "abc"..)

3. 数组长度,数组

array := [...]int{1, 2, 3}

4. go 命令

go test ./...

原文地址:https://www.cnblogs.com/wayland3/p/12179929.html