golang
已收录文章:14051篇
-
Go语言通过返回error值处理文件读取错误,需始终检查err并用defer关闭文件;小文件可用os.ReadFile简化操作,大文件需避免内存溢出;可使用os.IsNotExist判断特定错误类型,结合fmt.Errorf与%w包装错误以传递上下文,提升程序健壮性。300 收藏
-
以下源码都摘自 golang 1.16.15 版本。 1. channel 底层结构 Golang 中的 channel 对应的底层结构为 hchan 结构体(channel的源码位置在Golang包的 runtime/chan.go): type hchan struct { qcount uint // buf当前299 收藏
-
1.前言 时间和日期对于任何编程语言来说都是一个非常重要的包。 GO 语言 提供了 time 包来测量和显示时间。既可以根据所选时区获取当前时间,又可以使用 time 包添加当前时299 收藏
-
大家还是直接看代码吧~ package main import ( "fmt" ) func main() { start(NewB(C{})) start(NewB(D{})) } type A interface { what() } type B struct { A } type C struct { } func (b C) what() { fmt.Println("this is type C") }299 收藏
-
例如: 将json: { "name": "Laura" "age": "18" } 赋给struct: type PersonalInfo struct { Name string `json:"name"` Age string `json:"age"` } 用语句: person := PersonalInfo{} err := json.Unmarshal(json, &persona)//json为上面299 收藏
-
本文以一个简单事例的多种解决方案作为引子,用结构体Demo来总结各种并发读写的情况 一个数据竞态的case package main import ( "fmt" "testing" "time" ) func Test(t *testing.T) { fmt.Print("getNum(): ") for i :=299 收藏