03 2024 档案
摘要:package main import ( "fmt" "io" "strings" ) func main() { r := f1(-1) if r == nil { fmt.Println("r error") } else { r.Read([]byte("")) // panic: runt
阅读全文
摘要:Go 切片 切片结构 源码包 src/runtime/slice.go 中 定义 slice 的结构为 type slice struct { array unsafe.Pointer len int cap int } array 指针指向底层数组 len 表示切片长度 cap 表示切片容量 切片
阅读全文
摘要:Go 文件操作-读写文件 Go读取文件 整个文件读取进内存(适合读小文件) 1. 直接指定文件名读取 os.ReadFile() ioutil.ReadFile() (在 Go 1.16 开始,ioutil.ReadFile() 就等价于 os.ReadFile()) package main im
阅读全文
摘要:GO 反转字符串 package main import "fmt" func main() { str := "hello,world" bytes := []byte(str) lenBytes := len(bytes) forLen := lenBytes / 2 for i := 0; i
阅读全文