golang用到3个点(...)的地方

1. 用在可变参数函数(可变函数、变参函数)的参数上

parameter是指函数定义中参数,而argument指的是函数调用时的实际参数。
简略描述为:parameter=形参(formal parameter), argument=实参(actual parameter)。

func Sum(nums ...int) int {
    res := 0
    for _, n := range nums {
        res += n
    }
    return res
}
2. 用在调用 可变参数函数(可变函数、变参函数)的实际参数上
primes := []int{2, 3, 5, 7}
fmt.Println(Sum(primes...)) // 17
3. 用在 数组字面值(Array literals)上

数组字面值是一个封闭在方括号对([])中的包含有零个或多个表达式的列表,其中每个表达式代表数组的一个元素。当你使用数组字面值创建一个数组时,该数组将会以指定的值作为其元素进行初始化,而其长度被设定为元素的个数。

像这样

stooges := [...]string{"Moe", "Larry", "Curly"}

len(stooges) 是 3

或这样

numbers := [...]int{1, 2, 3, 4, 5}

此时 len(numbers) 等于 5

4. 用在 go 命令上

打印 x/net的所有包

$ cd $GOPATH/src/golang.org/x/net
$ go list ./...

golang.org/x/net/bpf
golang.org/x/net/context
golang.org/x/net/context/ctxhttp
golang.org/x/net/dict
golang.org/x/net/dns/dnsmessage
golang.org/x/net/html
golang.org/x/net/html/atom
golang.org/x/net/html/charset
golang.org/x/net/http/httpguts
golang.org/x/net/http/httpproxy
golang.org/x/net/http2
golang.org/x/net/http2/h2c
golang.org/x/net/http2/h2i
golang.org/x/net/http2/hpack
golang.org/x/net/icmp
golang.org/x/net/idna
golang.org/x/net/internal/iana
golang.org/x/net/internal/socket
golang.org/x/net/internal/socks
golang.org/x/net/internal/sockstest
golang.org/x/net/internal/timeseries
golang.org/x/net/ipv4
golang.org/x/net/ipv6
golang.org/x/net/nettest
golang.org/x/net/netutil
golang.org/x/net/proxy
golang.org/x/net/publicsuffix
golang.org/x/net/route
golang.org/x/net/trace
golang.org/x/net/webdav
golang.org/x/net/webdav/internal/xml
golang.org/x/net/websocket
golang.org/x/net/xsrftoken

go list ./... 中的./代表当前目录,...代表子目录