随笔分类 -  golang

go语言
摘要:一,官网: https://golang.google.cn/dl/ 二,下载 # wget https://golang.google.cn/dl/go1.25.4.linux-amd64.tar.gz 三,安装 解压: # tar -zxvf go1.25.4.linux-amd64.tar.g 阅读全文
posted @ 2025-11-15 08:43 刘宏缔的架构森林 阅读(243) 评论(0) 推荐(0)
摘要:进入项目目录后执行: $ go mod tidy 然后就可以执行run或build了 阅读全文
posted @ 2025-10-25 14:43 刘宏缔的架构森林 阅读(13) 评论(0) 推荐(0)
摘要:一,出现错误的代码: 1,代码 func startBackgroundJob() { ticker := time.NewTicker(1 * time.Minute) timeStop, _ := time.Parse("2006-01-02 15:04:05", "2025-07-08 09: 阅读全文
posted @ 2025-07-19 07:40 刘宏缔的架构森林 阅读(86) 评论(0) 推荐(0)
摘要:一,代码 //定时运行功能, func startBackgroundJob() { ticker := time.NewTicker(1 * time.Minute) go func() { for range ticker.C { // 执行后台任务逻辑 now := time.Now() // 阅读全文
posted @ 2025-07-19 07:39 刘宏缔的架构森林 阅读(11) 评论(0) 推荐(0)
摘要:一,执行顺序: 先进后出,类似于栈的特性 1,代码: func deferAndPanic() { defer func() { fmt.Println("defer1") }() defer func() { fmt.Println("defer2") }() defer func() { fmt 阅读全文
posted @ 2025-03-15 15:15 刘宏缔的架构森林 阅读(30) 评论(0) 推荐(0)
摘要:一,自定义io.Writer需要实现什么接口? package io type Writer interface { Write(p []byte) (n int, err error) } 二,Writer类代码: package fileWriter import ( "io" "os" "sy 阅读全文
posted @ 2025-02-23 17:38 刘宏缔的架构森林 阅读(140) 评论(0) 推荐(0)
摘要:一,代码: 1,controller/ImageController.go //得到详情 func (ic *ImageController) Detail(c *gin.Context) { // gin版本 ginVersion:=gin.Version // golang 版本 golangV 阅读全文
posted @ 2025-02-15 11:11 刘宏缔的架构森林 阅读(98) 评论(0) 推荐(0)
摘要:一,问题: 1, 看git的log $ git log commit c3b2a014a8c7ba3bceab73b853324e84bb84e016 (HEAD -> master) Author: liuhongdi <37@qq.com> Date: Thu Feb 13 13:30:22 2 阅读全文
posted @ 2025-02-15 11:11 刘宏缔的架构森林 阅读(60) 评论(0) 推荐(0)
摘要:一,代码: #!/bin/bash export BUILD_ID=dontKillme #所在目录 WORKSPACE=/data/gyweb #二进制文件名 BIN_NAME=industry USER=`whoami` echo "当前用户:$USER" echo "要启动的程序:$BIN_N 阅读全文
posted @ 2025-02-15 11:09 刘宏缔的架构森林 阅读(44) 评论(0) 推荐(0)
摘要:一,什么是context? 1,context是什么? context是 goroutine(协程) 的上下文,包含 goroutine 的运行状态、环境、现场等信息。context 主要用来在 goroutine 之间传递上下文信息,包括:取消信号、超时时间、截止时间、k-v 等。 2,conte 阅读全文
posted @ 2025-02-09 19:16 刘宏缔的架构森林 阅读(258) 评论(0) 推荐(0)
摘要:一,安装fresh库 $ go get github.com/pilu/fresh 二,遇到问题: 执行fresh时报错: $ fresh fresh:未找到命令 解决: $ go install github.com/pilu/fresh@latest 再次执行: $ go get github. 阅读全文
posted @ 2025-01-18 16:51 刘宏缔的架构森林 阅读(456) 评论(0) 推荐(0)
摘要:一,官网: 官方文档: https://pkg.go.dev/github.com/go-playground/validator/v10 代码地址: https://github.com/go-playground/validator 二、常用标记说明 标记 标记说明 例 required 必填 阅读全文
posted @ 2025-01-18 16:51 刘宏缔的架构森林 阅读(347) 评论(0) 推荐(0)
摘要:一,go应用的运行 我们没有在代码中设置daemon方式,这里用nohup运行应用: #!/bin/bash export BUILD_ID=dontKillme whoami WORKSPACE=/data/gy BIN_NAME=goappbinname PID=`ps -ef | grep $ 阅读全文
posted @ 2024-12-21 09:41 刘宏缔的架构森林 阅读(107) 评论(0) 推荐(0)
摘要:一,报错信息 在服务端运行编译好的二进制代码时报错: ./binapp: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./binapp) 这个是因为打包的开发环境与线上部署的运行环境之间系统核心包libc版本有差异 二, 阅读全文
posted @ 2024-12-21 09:40 刘宏缔的架构森林 阅读(3707) 评论(0) 推荐(0)
摘要:一,安装第三方库 $ go get github.com/spf13/viper 二,代码 1,配置文件 Database: DBType: mysql UserName: dbusername Password: dbpassword Host: 127.0.0.1:3306 DBName: db 阅读全文
posted @ 2024-12-21 09:38 刘宏缔的架构森林 阅读(193) 评论(0) 推荐(0)
摘要:一,安装第三方库: $ go get -u github.com/jordan-wright/email go: downloading github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible 阅读全文
posted @ 2024-12-14 13:06 刘宏缔的架构森林 阅读(281) 评论(0) 推荐(0)
摘要:一,指针和地址的操作 1,代码: 要掌握以下三个用法: *指针变量名 得到指针所指向的变量 *类型 表示这是一个此类型的指针 &变量 返回一个存放变量地址的指针 package main import ( "fmt" "reflect" ) func isPointer(v interface{}) 阅读全文
posted @ 2024-12-14 13:06 刘宏缔的架构森林 阅读(50) 评论(0) 推荐(0)
摘要:一,可以通过指针访问struct的变量 1,代码: package main import ( "fmt" "reflect" ) //判断是否指针 func isPointer(v interface{}) bool { return reflect.ValueOf(v).Kind() == re 阅读全文
posted @ 2024-12-14 13:06 刘宏缔的架构森林 阅读(35) 评论(0) 推荐(0)
摘要:一,说明: 不带星号的方法‌:这些方法定义在值接收者(value receiver)上。当你调用这些方法时,会操作该值的副本。如果方法内部修改了接收者,这些修改不会反映到原始值上。 ‌带星号的方法‌:这些方法定义在指针接收者(pointer receiver)上。当你调用这些方法时,会操作原始值的指 阅读全文
posted @ 2024-12-14 13:05 刘宏缔的架构森林 阅读(216) 评论(0) 推荐(0)
摘要:一,安装第三方库: $ go get -u github.com/disintegration/imaging 二,代码: //得到图片的宽高 fileImg, err := os.Open(filePath) // 替换为你的图片文件路径 if err != nil { //panic(err) 阅读全文
posted @ 2024-12-09 10:13 刘宏缔的架构森林 阅读(237) 评论(0) 推荐(0)