![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
golang
啊_sam
这个作者很懒,什么都没留下…
展开
-
gin bindJSON结构体中有不确定类型的字段
结构体中有不确定类型的字段,用interface{},BindJSON后根据输入自动存储对应类型,比如type student struct { Name string `json:"name"` Info interface{} `json:"info"`}比如,info的输入输入 类型 12 float64 “str” string {"str":"value"} ma...原创 2018-06-28 10:12:48 · 6448 阅读 · 2 评论 -
go mod 指定分支
go mod 指定分支在go.mod,库地址后面加上分支,如下XX.XX.com/XXX/XXX feature/f1然后,go build即可,自动改为sha码原创 2020-11-10 11:28:43 · 15868 阅读 · 3 评论 -
gorm struct使用自定义类型
自定义 需要实现 Scan(v interface{}) error 和 Value() (driver.Value, error) 方法如 自定义timetype MyTime time.Time //2006-01-02 15:04:05添加 Scan 和 ValueTimeFormat := "2006-01-02 15:04:05"// Scan is scanning value from gormfunc (t *MyTime) Scan(v interface{}) error原创 2020-09-27 10:16:23 · 1223 阅读 · 0 评论 -
go mod 指定commit版本
go mod 指定commit版本在go.mod所在目录执行go get XX.XX.com/XXX/XXX@f0b928XX即 go get 项目@sha原创 2020-09-23 17:29:44 · 7348 阅读 · 0 评论 -
golang 并发锁在struct里的陷阱
错误代码type Test struct { sync.Mutex M map[int]int}func main() { buf = make([]Test , 2); buf[0] = Test{M: make(map[string]string)} buf[1] = Test{M: make(map[string]string)} var wg sync.WaitGroup for i := 0; i < 100; i++ { wg.Add(1) go func原创 2020-09-21 17:20:08 · 1938 阅读 · 2 评论 -
性能调试
性能调试1、http服务端package mainimport ( _ "net/http/pprof" // 会自动注册 handler 到 http server,方便通过 http 接口获取程序运行采样报告)func main() { // runtime.GOMAXPROCS(1) // 限制 CPU 使用数,避免过载 runtime.SetMutexProfileFraction(1) // 开启对锁调用的跟踪 runtime.SetBlockProfileRate(1) /原创 2020-08-03 11:36:45 · 367 阅读 · 0 评论 -
性能相关代码
性能1、数组和切片能有数组,尽量用数组,会提供效率数组是在栈上完成切片在堆上分配内存,会GC原创 2020-08-03 11:35:30 · 194 阅读 · 2 评论 -
go env 设置
go mod1、go1.11以上版本,启动go mod设置GO111MODULEgo env -w GO111MODULE=on2、启动代理设置GOPROXY,解决go get失败问题,如vscode的golint等工具go env -w GOPROXY=https://goproxy.cn,direct3、设置私有库设置GOPRIVATE,域名无需http 或 gitgo env -w GOPRIVATE=私有库域名...原创 2020-08-03 11:34:47 · 475 阅读 · 2 评论