Go官方包函数中文翻译

***

import "strings"

  1. func Join(a []string, sep string) string

    1. Join concatenates the elements of a to create a single string. The separator string sep is placed between elements in the resulting string.
    2. 翻译: 根据切片a中的元素生成一个字符串, sep分割字符串被放置在生成的字符串中间.
      例如:
      s := []string{"hah", "nihao", "wode"} fmt.Println(strings.Join(s, ",, ")) fmt.Println(strings.Join(s, "")) 输出: hah,, nihao,, wode hahnihaowode


Go内建函数

  1. func append(s []T, vs …T) []T

    1. append 的第一个参数 s 是一个元素类型为 T 的切片, 其余类型为 T 的值将会追加到该切片的末尾。
    2. append 返回值: 一个包含原切片所有元素加上新添加元素的切片。
    3. 当 s 的底层数组太小,不足以容纳所有给定的值时,它就会分配一个更大的数组。 返回的切片会指向这个新分配的数组。
  2. func make([]T, len, cap) []T

    1. 切片可以使用内置函数 make 创建;
    2. 参数: []T: T 为切片中元素的类型;
      len : 该切片的长度;
      cap : 该切片的容量;
      当参数为 2个时, 第二个参数即为长度,也是容量. 即len == cap
    3. 返回值: 为该数组对应的切片;
    4. 使用内置函数 len 和 cap 获取切片的长度和容量信息。
      例如:
      s := make([]byte, 5) len(s) == 5 cap(s) == 5
  3. func copy(dst, src []T) int

    1. copy 函数将源切片的元素复制到目的切片。 它返回复制元素的数目。
      copy 函数支持不同长度的切片之间的复制(它只复制较短切片的长度个元素), 所以保证 src的容量 <= dst的容量.
      此外, copy 函数可以正确处理源和目的切片有重叠的情况。
      例如:
      func AppendByte(slice []byte, data ...byte) []byte { m := len(slice) n := m + len(data) if n > cap(slice) { // if necessary, reallocate // allocate double what's needed, for future growth. newSlice := make([]byte, (n+1)*2) copy(newSlice, slice) slice = newSlice } slice = slice[0:n] copy(slice[m:n], data) fmt.Println(slice) return slice }
  4. func append(s []T, x ...T) []T

    1. append 函数将 x 追加到切片 s 的末尾,并且在必要的时候增加容量。
    2. 如果是要将一个切片追加到另一个切片尾部,需要使用 ... 语法将第2个参数展开为参数列表。
      例如:
      a := []string{"John", "Paul"} b := []string{"George", "Ringo", "Pete"} a = append(a, b...) // equivalent to "append(a, b[0], b[1], b[2])" // a == []string{"John", "Paul", "George", "Ringo", "Pete"}
  5. Range

    1. for 循环的 range 形式可遍历切片或映射
    2. 当使用 for 循环遍历切片时,每次迭代都会返回两个值。 第一个值为当前元素的下标,第二个值为该下标所对应元素的一份副本.
    3. 可以将下标或值赋予 _ 来忽略它
    4. 若你只需要索引,去掉 , value 的部分即可
      例如:
      func main() { var result = []int{1, 2, 4, 8, 16, 32, 64, 128} for i, v := range result { fmt.Printf("i = %d, value = %d\n", i, v) } for i:= range result { fmt.Printf("i = %d\n", i) } } 输出: i = 0, value = 1 i = 1, value = 2 i = 2, value = 4 i = 3, value = 8 i = 4, value = 16 i = 5, value = 32 i = 6, value = 64 i = 7, value = 128 i = 0 i = 1 i = 2 i = 3 i = 4 i = 5 i = 6 i = 7
    5. 当使用 for 循环遍历 map结构(即映射)时, 返回两个值:第一个值为 key, 第二个值为key对应的value.
      当map结构中无元素时, 该循环不会进入.直接跳过.


import "io/ioutil"

  1. func ReadFile(filename string) ([]byte, error)

    1. ReadFile reads the file named by filename and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
    2. 翻译: 读取filename 文件, 返回出文件文件全部内容. 成功: err == nil; 失败: err == EOF;
      注意: 因为ReadFile() 读取的是整个文件, 所以在正常读取过程中, 文件末尾的EOF并不会当做错误进行报告.


import "net"

  1. func ResolveTCPAddr(net, addr string) (*TCPAddr, error)

    1. ResolveTCPAddr parses addr as a TCP address of the form "host:port" or "[ipv6-host%zone]:port" and resolves a pair of domain name and port name on the network net, which must be "tcp", "tcp4" or "tcp6". A literal address or host name for IPv6 must be enclosed in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80".
      Resolving a hostname is not recommended because this returns at most one of its IP addresses.
    2. 翻译: 该函数将参数 addr解析为TCP格式的地址块, 并且根据net参数解析一对域名和端口, net必须为: TCP..., 自满地址或主机名为IPV6的解析结果必须包含在括号中. 解析一个主机名不推荐使用该函数,因为它最多返回一个IP地址.
  2. func (c *IPConn) Read(b []byte) (int, error)

    1. Read implements the Conn Read method.
    2. 翻译:该函数实现了从套接字中读取数据, 返回读取的长度和出错信息. 读取的内容拷贝在参数b中. 当该套接字关闭或出错, err被赋值错误信息返回. 接收成功, err为nil.
  3. func (c *TCPConn) LocalAddr() Addr

    1. LocalAddr returns the local network address. The Addr returned is shared by all invocations of LocalAddr, so do not modify it.
    2. 翻译: 该函数返回一个本地的网路地址. 这个调用函数返回的地址被所有调用共享,不要去修改它..
  4. func (c *IPConn) RemoteAddr() Addr

    1. RemoteAddr returns the remote network address. The Addr returned is shared by all invocations of RemoteAddr, so do not modify it.
    2. 翻译: 该函数返回一个 远程的网络地址. 该掉用函数返回的地址 被整台机器共享, 不要去修改它.
  5. func Dial(network, address string) (Conn, error)

    1. Dial connects to the address on the named network.
      Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only), "udp", "udp4" (IPv4-only), "udp6" (IPv6-only), "ip", "ip4" (IPv4-only), "ip6" (IPv6-only), "unix", "unixgram" and "unixpacket".
      For TCP and UDP networks, addresses have the form host:port. If host is a literal IPv6 address it must be enclosed in square brackets as in "[::1]:80" or "[ipv6-host%zone]:80". The functions JoinHostPort and SplitHostPort manipulate addresses in this form. If the host is empty, as in ":80", the local system is assumed.
    2. 翻译: 该函数依据 network 链接address指向的地址.
      network标志有...
      对于 TCP,UDP标识, address格式为host:port, 如果host为IPV6, 则必须被包含在方括号中. 函数JoinHostPort和SplitHostPort控制host格式. 如果host为空, 默认为本机.
      注意: 1.当network == TCP 时, client链接address地址, 服务器未监听时, 该函数调用会立即报错.因为 TCP协议的server端, 有socket(), bind(), listen(), accept(), 随后才会在链接上的套接字接收信息.
      注意: 2.当network == UDP 时, client链接address地址, 即使服务器未开启, 该函数也会成功.因为 UDP协议的server端, 只有socket(), bind(), 然后即在该套接字端口接收来自客户端的信息


import "runtime"

  1. func Caller(skip int) (pc uintptr, file string, line int, ok bool)

    1. Caller reports file and line number information about function invocations on the calling goroutine's stack. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of Caller. (For historical reasons the meaning of skip differs between Caller and Callers.) The return values report the program counter, file name, and line number within the file of the corresponding call. The boolean ok is false if it was not possible to recover the information.
    2. 翻译:返回调用函数的行号和文件名

import "os"

  1. func Exit(code int)

    1. Exit causes the current program to exit with the given status code. Conventionally, code zero indicates success, non-zero an error. The program terminates immediately; deferred functions are not run.
    2. 翻译: exit函数使当前程序退出,code为退出状态. 同常: 0标识正常退出, 非0 标识错误.. 作用为: 程序立即终止, 并且,并且,注意:defer 关键字中的函数不会被执行.
  2. func


声明:本人学习期间持续翻译中,水平不高,只能这么生硬的翻译。有不对的请指正:yyxyong@163.com

Go 语言官方包函数中文翻译的更多相关文章

  1. GitHub官方介绍(中文翻译)

    注:本人亲自翻译,转载请注明出处. 官方链接地址 http://guides.github.com/activities/hello-world/ Hello World 项目在计算机编程界是一项历史 ...

  2. 【转】QT Graphics-View官方介绍(中文翻译)

    一.GraphicsView框架简介 QT4.2开始引入了Graphics View框架用来取代QT3中的Canvas模块,并作出了改进,Graphics View框架实现了模型-视图结构的图形管理, ...

  3. Kubernetes tutorial - K8S 官方入门教程 中文翻译

    官方教程,共 6 个小节.每一小节的第一部分是知识讲解,第二部分是在线测试环境的入口. kubectl 的命令手册 原文地址 1 创建集群 1.1 使用 Minikube 创建集群 Kubernete ...

  4. Superset 官方入门教程中文翻译

    本文翻译自 Superset 的官方文档:Toturial - Creating your first dashboard 最新版本的 Superset 界面与功能上与文档中提到的会有些许出入,以实际 ...

  5. Umbraco官方技术文档 中文翻译

    Umbraco 官方技术文档中文翻译 http://blog.csdn.net/u014183619/article/details/51919973 http://www.cnblogs.com/m ...

  6. tesseract中文语言文件包 下载

    tesseract中文语言文件包 下载 tesseract中文语言文件包 下载 tesseract中文语言文件包 下载 下载地址是:https://github.com/tesseract-ocr/l ...

  7. Ubuntu配置图形桌面LXDE和VNC、中文语言包、中文输入法

    Ubuntu配置图形桌面LXDE和VNC.中文语言包.中文输入法 http://www.lijiejie.com/ubuntu-vps-config-lxde-vnc/ LXDE是Ubuntu图形桌面 ...

  8. Socket编程(C语言实现):bind()函数英文翻译

    本篇翻译的bind()函数,我参考的国外网站是: bind 朋友们可以自由转载我对英文的中文翻译,但是对于"作者注:"的描述,转载时请注明出处和作者,否则视为侵权. 下面是翻译的正 ...

  9. Socket编程(C语言实现):socket()函数英文翻译

    最近开始研究使用Socket API来网络编程,想着把自己的感想.感悟写下来.我发现在编程之外还有不少概念性的东西要学习.我觉得应该有以下几点吧: 1.得了解下计算机网络的基本概念,如OSI的7层模型 ...

随机推荐

  1. [Algorithm] Universal Value Tree Problem

    A unival tree (which stands for "universal value") is a tree where all nodes under it have ...

  2. (笔试题)小米Git

    题目: git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需 ...

  3. android google map v1 v2 v3 参考

    V1,V2已经不被推荐使用,谷歌强烈推荐使用V3. 本人在选择时着实纠结了良久,现在总结如下: 对于V1,现在已经申请不到API KEY了,所以不要使用这个版本.这个是网址:https://devel ...

  4. 带"叉叉"的GridView

    由于需要用到“删除图片”的功能,需要写这样一个小demo: 对之前博文的修改 发现imageView监听点击事件 效果实在不敢恭维,因此换个方式:设置Touch的监听函数, 下面的Demo没有改过来哈 ...

  5. oracle 之监听保护

    今天是2013-08-24,不对刚刚过了12点,应该是2013-08-25日,今天我的同事对数据库 进行监听安全加固失败,然后 我的哥们也做了同样的实验,结果还是失败,至此我不知道 什么原因,在此想对 ...

  6. 微信小程序 - 获取所在位置(省、市、区)

    实现步骤 1. 获取当前经纬度 2. 调用腾讯(百度.高德)地图对应的请求地址,一般都会有独一的key, 譬如 腾讯地图调用地址: https://apis.map.qq.com/ws/geocode ...

  7. whereis 命令(转)

    原文:http://www.cnblogs.com/peida/archive/2012/11/09/2761928.html whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b) ...

  8. HDUOj Ignatius and the Princess III 题目1002

     母函数  组合数学 #include<stdio.h> int c1[125]; int c2[125]; int main() { int n,i,j,k; while(scanf ...

  9. margin赋值为负值的几种效果(负值像素,负值百分数)

    1.margin-top为负值像素 margin-top为负值像素,偏移值相对于自身,其后元素受影响,见如下代码: <!DOCTYPE html> <html lang=" ...

  10. osx下查看jar文件

    jar是java class的打包文件,我们能够将自己的项目打包为jar文件执行,也能够打包后当做第三方包查看,有时候我们须要查看一下一个jar文件里是否还有某个类以及对应的包,我们能够採用下面两种方 ...