zoukankan      html  css  js  c++  java
  • go中三个点(...)用法

    go命令中三个点含义

    An import path is a pattern if it includes one or more "..." wildcards, each of which can match any string, including the empty string and strings containing slashes.

    Such a pattern expands to all package directories found in the GOPATH trees with names matching the patterns.

    As a special case, x/... matches x as well as x's subdirectories. For example, net/... expands to net and packages in its subdirectories.

    参考:https://blog.csdn.net/dongfengkuayue/article/details/52769322

    如“go build ./...",编译当前目录下所有go包。

    golang中的三个点"…"的用法

    ‘…’ 其实是go的一种语法糖。 

    它的第一个用法主要是用于函数有多个不定参数的情况,可以接收多个不确定数量的参数。  

    第二个用法是slice可以被打散进行传递。

    示例如下:

    func test1(args ...string) {        //可以接受任意个string参数
        for _, v:= range args{
            fmt.Println(v)
        }
    }
    
    func main(){
    var strss= []string{
            "qwr",
            "234",
            "yui",
            "cvbc",
        }
        test1(strss...)      //切片被打散传入
    }

    结果:

    qwr
    234
    yui
    cvbc

    其中strss切片内部的元素数量可以是任意个,test1函数都能够接受。

    第二个例子: 

    var strss= []string{
            "qwr",
            "234",
            "yui",
    
    }
    var strss2= []string{
            "qqq",
            "aaa",
            "zzz",
            "zzz",
    }
    strss=append(strss,strss2...)      //strss2的元素被打散一个个append进strss
    fmt.Println(strss)

    结果:

    [qwr 234 yui qqq aaa zzz zzz]

    参考:https://blog.csdn.net/jeffrey11223/article/details/79166724

  • 相关阅读:
    Kubernetes笔记 (2)
    Kubernetes笔记(3)
    Kubernetes笔记 (1)
    《深入浅出React和Redux》(4)
    【从0安装】xshell和xftp
    【从0安装】Sourcetree
    postman测试需要登录的接口
    vue自定义滚动条组件-vuebar组件
    charles 抓包http 和 https
    pycharm 面板颜色调整和中文汉化
  • 原文地址:https://www.cnblogs.com/embedded-linux/p/10961368.html
Copyright © 2011-2022 走看看