摘要: 字符串类型的带小数点的数字转int number := "12.123" cast.ToInt(number) // 0 错误 cast.ToInt(cast.ToFloat32(number)) // 12 正确 零值字符串无法转为int类型 number := "08" cast.ToInt(n 阅读全文
posted @ 2024-03-28 11:40 元気田支店长 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 注:文章参考https://zhuanlan.zhihu.com/p/679475977 for循环 循环共享变量问题 Go在1.22版本之前,for 循环迭代器的变量是一个单一变量,使用不当,会导致意想不到的行为,可能会造成共享循环变量的问题。 如依旧要使用旧版本,可以主动配置 GOEXPERIM 阅读全文
posted @ 2024-03-03 10:21 元気田支店长 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 安装dlv 执行go install 安装dlv go install github.com/go-delve/delve/cmd/dlv@latest 执行 dlv version 查看是否安装成功 $ dlv version Delve Debugger Version: 1.22.0 Buil 阅读全文
posted @ 2024-02-26 16:10 元気田支店长 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 出现问题 下面代码为使用 golang 给用户发送邮件功能: package main import ( "fmt" "gopkg.in/gomail.v2" ) func main() { subject := "邮件标题" sendUserEmail := []string{"xxx@163.c 阅读全文
posted @ 2024-02-26 11:16 元気田支店长 阅读(5) 评论(0) 推荐(0) 编辑
摘要: 没有如 ll 这种快捷命令 vim /root/.bashrc 后添加以下内容 export LS_OPTIONS='--color=auto' alias ls='ls $LS_OPTIONS' alias ll='ls $LS_OPTIONS -l' alias l='ls $LS_OPTION 阅读全文
posted @ 2024-02-05 10:26 元気田支店长 阅读(4) 评论(0) 推荐(0) 编辑
摘要: 工具安装 下载地址:https://github.com/voidint/g/releases 中文文档:https://github.com/voidint/g/blob/master/README_CN.md 常用命令 # 列出当前已安装的golang版本 g ls # 列出所有可安装的gola 阅读全文
posted @ 2024-01-23 09:46 元気田支店长 阅读(75) 评论(0) 推荐(0) 编辑
摘要: 下载源码 源码下载地址:https://dev.mysql.com/downloads/mysql/ 找到对应版本进行下载上传至服务器 编译安装 使用cmake命令进行安装 cd mysql-8.0.35 mkdir bld cd bld cmake -DCMAKE_INSTALL_PREFIX=/ 阅读全文
posted @ 2023-12-05 15:46 元気田支店长 阅读(134) 评论(0) 推荐(0) 编辑
摘要: 出现问题: 在开发过程中,遇到这样一个问题,GORM Model 如下: type Test struct { ... cloumnType uint8 `gorm:"not null;default:0"` ... } 其中有一个类型字段,数据范围是1-10 所以使用uint8字段来存储,在查询某 阅读全文
posted @ 2023-10-16 11:34 元気田支店长 阅读(300) 评论(0) 推荐(0) 编辑
摘要: 图片上绘制文字 package main import ( "github.com/golang/freetype" "image" "image/draw" "image/png" "io/ioutil" "log" "os" ) // TextInfo 文字信息 type TextInfo st 阅读全文
posted @ 2023-08-07 16:58 元気田支店长 阅读(383) 评论(0) 推荐(0) 编辑
摘要: Go标准库中的context包,提供了goroutine之间的传递信息的机制,信号同步,除此之外还有超时(timeout)和取消(cancel)机制。概括起来,Context可以控制子goroutine的运行,超时控制的方法调用,可以取消的方法调用。 context核心数据结构 Context in 阅读全文
posted @ 2023-06-25 09:56 元気田支店长 阅读(13) 评论(0) 推荐(0) 编辑