随笔分类 -  Go

摘要:1.switch switch后带表达式时,switch-case只能模拟相等的情况;如果不带表达式(即 空switch),case后就可以跟任意的条件表达式,例: switch { case add(5) > 10: fmt.Println("right") default: fmt.Printl 阅读全文
posted @ 2023-01-27 16:55 balabalahhh 阅读(13) 评论(0) 推荐(0) 编辑
摘要:1.为任意类型添加方法(包括系统定义的) 例: 1 type UserMap map[int]User 2 3 func (um UserMap) GetUser(id int) User{ 4 return um[id] 5 } 2.匿名结构体(通常用于只使用一次的情况) 资料里看到的一种写法: 阅读全文
posted @ 2023-01-20 21:43 balabalahhh 阅读(45) 评论(0) 推荐(0) 编辑
摘要:一.字符串拼接1.加号连接 2.fmt.Sprintf(format string,a ...interface{})string 3.string.Join(elems []string, sep string)string 4.使用strings.Builder、bytes.Buffer(两者速 阅读全文
posted @ 2023-01-17 21:02 balabalahhh 阅读(20) 评论(0) 推荐(0) 编辑
摘要:binary.BigEndian.PutUint32() uint32类型的数字在字节流切片上占4个字节 PutUint32()专门用来处理固定长度的数字 相对:binary.BigEndian.Uint32 参考文章:https://www.jianshu.com/p/3d187474ad0c 阅读全文
posted @ 2023-01-15 16:35 balabalahhh 阅读(183) 评论(0) 推荐(0) 编辑
摘要:C 的 read,pread 这两个接口对应的是 Golang 的 Read 和 ReadAt 这两个接口,C 的 read,pread 除了传入参数有区别,其他语义是完全一致的。golang有区别 Golang 里面 Read 接口对于读的结果有这么几种情况: 读成功了,数据完全填充 buffer 阅读全文
posted @ 2023-01-14 16:35 balabalahhh 阅读(186) 评论(0) 推荐(0) 编辑
摘要:1.配置环境变量 对于Linux和Mac用户,mkdir /data/go_path vim ~/.bashrc加入以下几行 export GOROOT=/usr/local/go ($GOROOT和$GOPATH这两个路径完全可以自定义) export GOPATH=/data/go_path e 阅读全文
posted @ 2023-01-14 15:34 balabalahhh 阅读(29) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示