随笔分类 -  Go

摘要:1、现象 Go下载模块提示连接失败 dial tcp 142.251.42.241:443: connectex: A connection attempt failed because the connected party did not properly respond after a per 阅读全文
posted @ 2021-12-20 22:02 南风丶轻语 阅读(3355) 评论(0) 推荐(1) 编辑
摘要:Go语言获取当前函数名称和上一层调用者函数名称 假设main函数调用CallTest1函数,CallTest1函数又调用Test1函数,Test1函数又调用getFunName函数,我们可以依次都获取出对应的函数名称 我们可以称函数getFunName为当前函数 然后称Test1函数为调用者函数 反 阅读全文
posted @ 2021-12-02 16:32 南风丶轻语 阅读(961) 评论(0) 推荐(0) 编辑
摘要:1、Go语言map与json串相互转化 map转为Json串(本质是string),先把map转为byte数组,再把byte数组转为Json串 Json串(本质是string)转为map,先把Json串转为byte数组,再把byte数组转为map go package main import ( " 阅读全文
posted @ 2021-12-01 11:17 南风丶轻语 阅读(8784) 评论(0) 推荐(0) 编辑
摘要:1、时间与字符串以及时间戳的相互转换 Time类型 >string类型 string类型 >Time类型 Time类型 >时间戳int64类型(秒) 时间戳int64类型(秒) >Time类型 package main import ( "fmt" "time" ) func main() { // 阅读全文
posted @ 2021-12-01 10:43 南风丶轻语 阅读(1855) 评论(0) 推荐(0) 编辑
摘要:1、什么是字符串❓ 是只读的字节数组 本质 字符串是不可变的 是一串连续的内存地址 内存表现 数据结构如下 // StringHeader is the runtime representation of a string. 是字符串的运行时表示。 // It cannot be used safe 阅读全文
posted @ 2021-11-30 09:54 南风丶轻语 阅读(402) 评论(0) 推荐(0) 编辑
摘要:解决go gin框架 binding:"required"`无法接收零值的问题 1、现象: ​ 在go中gin框架中,需要接收前端参数时,参数必填,我们一般添加binding:"required"`标签,这样前端参数不给时,gin框架会自动校验,给出error。 ​ gin的参数校验是基于valid 阅读全文
posted @ 2021-10-25 11:55 南风丶轻语 阅读(7267) 评论(1) 推荐(1) 编辑
摘要:Go输出带指针的结构体 1、场景 当结构体带指针时,输出结构体,指针类型输出的是地址,而不是具体的值,例如 package main import "fmt" // Student 学生信息 type Student struct { Name *string Age *int Sex string 阅读全文
posted @ 2021-10-19 11:26 南风丶轻语 阅读(485) 评论(0) 推荐(0) 编辑
摘要:1、安装包地址 https://golang.org/dl/ 2、下载后双击,一路next就行 3、配置环境变量 (1)安装包的默认安装路径是 /usr/local/go (2)执行命令来配置环境变量 cd ~ 切换到当前用户下 vim .bash_profile 编辑该文件 添加一句 export 阅读全文
posted @ 2021-08-06 17:49 南风丶轻语 阅读(230) 评论(0) 推荐(0) 编辑