随笔分类 -  go 阅后随记

摘要:Go module遵循语义化版本规范 2.0.0 major.minor.patch 样板分析 ##1. model path 一行是module path, 一般采用仓库地址方式定义。这样我们获取一个module的时候,就可以到它的仓库中去查询,或者让go proxy到仓库中去查询。 如果版本大于 阅读全文
posted @ 2022-04-11 17:11 fanzou 阅读(1863) 评论(0) 推荐(1)
摘要:The concrete value stored in an interface is not addressable, in the same way that a map element is not addressable. 意思具体值赋值给 interface 类型后与 map 中的元素一 阅读全文
posted @ 2022-03-02 15:59 fanzou 阅读(250) 评论(0) 推荐(0)
摘要:import ( "encoding/json" "fmt" ) type AutoGenerated struct { Age int `json:"age"` Name string `json:"name"` Child []int `json:"child"` } func main() { 阅读全文
posted @ 2020-10-26 11:32 fanzou 阅读(574) 评论(0) 推荐(0)
摘要:1、解析时,结构体的Tag使用 tag就是标签,给结构体的每个字段打上一个标签,标签冒号前是类型,后面是标签名; - json解析时用 json,同时注意bson,bson用于mongdb的存储解析 - omitempty,可以在序列化的时候忽略0值或者空值 - type,在序列化或者反序列化的时候 阅读全文
posted @ 2020-09-18 19:15 fanzou 阅读(205) 评论(0) 推荐(0)
摘要:操作的参数传入基本都是结构体的指针,同时完成CURD后,指针指向的结构体数据也将随着更新 #1 创建 Create type User struct { ID int64 Name string `gorm:"default:'galeone'"` Age int64 } var user= Use 阅读全文
posted @ 2020-09-08 19:29 fanzou 阅读(590) 评论(0) 推荐(0)
摘要:一、基于slice,简单实现 queue []*wantConn //入队 queue = append(queue, w) //出队 v := queue[0] queue[0] = nil queue = queue[1:] 但是这会存在问题,随着频繁的入队与出队操作,切片queue的底层数组, 阅读全文
posted @ 2020-08-24 19:11 fanzou 阅读(427) 评论(0) 推荐(0)
摘要:#1.通常处理 错误需要开发者主动捕获,同时只能获取是什么错误,无法获悉调用栈(确定具体哪一行,也就是不知道那行出了错误) _,err := func() if err != nil { //错误处理 } #2.几种常见创建错误的方法 1)errors.New() err1 := errors.Ne 阅读全文
posted @ 2020-08-24 11:35 fanzou 阅读(376) 评论(0) 推荐(0)