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

  • 相关阅读:
    万维网
    MySQL客户端输出窗口显示中文乱码问题解决办法
    mysql数据库delete数据时不支持表别名
    Java 实现在固定区间内随机生成整数
    【面试】MySQL 中NULL和空值的区别?
    一个因MySQL大小写敏感导致的问题
    windows查看服务的状态
    不就是Select Count语句吗,竟然能被面试官虐的体无完肤!
    Java 代码的精优化
    java服务宕机原因查询
  • 原文地址:https://www.cnblogs.com/embedded-linux/p/10961368.html
Copyright © 2011-2022 走看看