go
coding上下求索
学无止境,吾将上下而求索!
QQ:743701947 欢迎一起交流学习
The greater the ability, the greater the responsibility.
展开
-
golang中给数据库datetime格式赋值
1、定义数据库表映射结构体如上,create_time字段在表里面是datetime格式。2、如果CreateTime不给值,在存库时,create_time字段的值为NULL。3、赋值时,如下代码。原创 2023-09-07 10:26:33 · 1019 阅读 · 0 评论 -
golang Excelize 设置数字单元格为文本格式
golang Excelize 设置数字单元格为文本格式。原创 2022-09-30 16:31:12 · 1131 阅读 · 0 评论 -
go-bindata安装问题
在go的版本>=1.17时,使用如下命令进行安装go-bindata。go-bindata对go的版本不同是有不一样的安装方式。原创 2022-07-20 16:43:03 · 3607 阅读 · 0 评论 -
golang报错fatal error: all goroutines are asleep - deadlock
问题描述报错fatal error: all goroutines are asleep - deadlockgolang中无缓冲chan的数据传递是同步的,处理不当会造成死锁原创 2022-07-06 10:08:11 · 4827 阅读 · 0 评论 -
golang 解决invalid argument tmp (type interface {}) for len
此处会报invalid argument n1[0] (type interface {}) for len的错误,需要将其转换对应类型后再获取len的结果,如下:原创 2022-06-24 10:06:08 · 7320 阅读 · 0 评论 -
golang 队列(数组实例)
type ArrQue struct { Qs []string Size int Lock sync.Mutex}func (t *ArrQue) ArrAdd(data string) { t.Lock.Lock() defer t.Lock.Unlock() t.Qs = append(t.Qs, data) t.Size += 1}func (t *ArrQue) ArrPop() string { t.Lock.Lock.原创 2022-05-17 16:04:59 · 9321 阅读 · 0 评论 -
golang协程并发量控制
func main() { ch := make(chan int, 3) for i := 0; i < 10; i++ { ch <- 1 go func(j int) { time.sleep(1 * time.Second) <-ch }(i) } close(ch)}原创 2022-05-17 14:31:10 · 7909 阅读 · 0 评论 -
gorm 处理bytea、jsonb类型数据表字段
1、tbl_tmp表里面字段a是bytea类型建数据表映射结构体如下:type Tmp struct { A []byte `gorm:"column:a"`}2、tbl_tmp表里面字段b是jsonb类型建数据表映射结构体如下:type Tmp struct { B string `gorm:"column:b"`}...原创 2022-05-12 11:37:20 · 8745 阅读 · 0 评论 -
golang 反射实现结构体copy
type A struct { One string Two int}type B struct { One string Two int}func CopyStruct(src, dst interface{}) error { sval := reflect.ValueOf(src).Elem() dval := reflect.ValueOf(dst).Elem() for i := 0; i < sval.NumField.原创 2022-03-18 11:48:12 · 8750 阅读 · 2 评论 -
golang里面关于map[string]interface{}取值问题
正确的取值方法:a := data["int"].(int)b := data["string"].(string)原创 2021-09-10 15:38:52 · 10511 阅读 · 1 评论 -
golang 检查目录中指定后缀文件的行数总和
func CountLineNum(path, key string) (count int) { files, err := ioutil.ReadDir(path) if err == nil { for _, fileInfo := range files { newPath := path + "\\" + fileInfo.Name() if fileInfo.IsDir() { cou...原创 2021-07-17 14:56:58 · 7881 阅读 · 0 评论