首页 技术 正文
技术 2022年11月11日
0 收藏 550 点赞 2,687 浏览 1322 个字

1.字符串空为””

2. 传递的数组是原数组的拷贝,所以是无法通过传递数组的方法去修改原地址的数据的。在GO语言中除了切片(slice)、集合(map)、通道(channel)和接口(interface)之外,其它的都是值传递

3.在多行的Slice、Array和Map语句中遗漏逗号

package mainfunc main() {
x := []int{
1,
2 //error,需要加,
}
_ = x
}

Compile Errors:

syntax error: unexpected semicolon or newline, expecting comma or }

4.闭包中使用的变量若非作为参数传递,则都是引用传递

package mainimport (
"fmt"
)func main() {
s := []string{"a","b","c"}
for _,v := range s {
go func () {
fmt.Println(v)
}()
}
select {}
}

输出

c
c
c
fatal error: all goroutines are asleep - deadlock!

5.append 方法在添加数据后超过原始长度会重新创建新的存储空间

package mainimport (
"fmt"
)func Ping(s []int) {
s = append(s,3)
}
func main() {
s := make([]int, 0)
fmt.Println(s)
Ping(s)
fmt.Println(s)
}

  输出结果:

[]
[]

  最优写法:

package mainimport (
"fmt"
)func Ping(s []int) []int {
s = append(s,3)
return s
}
func main() {
s := make([]int, 0)
fmt.Println(s)
s = Ping(s)
fmt.Println(s)
}

  6.使用time的Format时,使用自带常量

const (
ANSIC = "Mon Jan _2 15:04:05 2006"
UnixDate = "Mon Jan _2 15:04:05 MST 2006"
RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
RFC822 = "02 Jan 06 15:04 MST"
RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST"
RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
RFC3339 = "2006-01-02T15:04:05Z07:00"
RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
Kitchen = "3:04PM"
// Handy time stamps.
Stamp = "Jan _2 15:04:05"
StampMilli = "Jan _2 15:04:05.000"
StampMicro = "Jan _2 15:04:05.000000"
StampNano = "Jan _2 15:04:05.000000000"
)

  

下一篇: gateway 配置
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,962
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781