文章分类 -  go语言

摘要:go语言实战的好文章摘录Go 错误处理指北:Defer、Panic、Recover 三剑客 https://jianghushinian.cn/2024/10/13/go-error-guidelines-defer-panic-recover/ 阅读全文
posted @ 2024-11-06 13:26 Jikefan 阅读(10) 评论(0) 推荐(0)
摘要:package main import ( "bytes" "encoding/json" "fmt" "io/ioutil" "net/http" ) type Payload struct { Name string `json:"name"` Age int `json:"age"` } fu 阅读全文
posted @ 2024-07-12 14:46 Jikefan 阅读(19) 评论(0) 推荐(0)
摘要:在 Go 语言中,可以使用 mongo-go-driver 来操作 MongoDB。这是一个官方的 MongoDB 驱动程序。以下是如何使用 Go 语言操作 MongoDB 的示例,包括连接到 MongoDB、插入数据、查询数据、更新数据和删除数据。 安装 MongoDB Go 驱动程序 首先,安装 阅读全文
posted @ 2024-06-26 16:25 Jikefan 阅读(74) 评论(0) 推荐(0)
摘要:go实现备忘录模式备忘录模式让我们可以保存对象状态的快照。 你可使用这些快照来将对象恢复到之前的状态。 这在需要在对象上实现撤销-重做操作时非常实用。 目录结构 ├── caretaker.go ├── memento.go ├── memento_test.go └── originator.go memento. 阅读全文
posted @ 2024-06-19 10:37 Jikefan 阅读(12) 评论(0) 推荐(0)
摘要:go recovergo recover运用 package recovery_test import ( "fmt" "testing" ) func TriggerPanic() { a := []int{1, 2, 3} fmt.Println(a[4]) } func RecoverError() { fmt. 阅读全文
posted @ 2024-05-17 14:35 Jikefan 阅读(13) 评论(0) 推荐(0)
摘要:go的Context运用记录当遇到慢速查询时的超时处理 package main import ( "context" "fmt" "net/http" "time" ) func simulateSlowDatabaseQuery(ctx context.Context) (string, error) { select { 阅读全文
posted @ 2024-04-30 13:38 Jikefan 阅读(6) 评论(0) 推荐(0)