
golang
_细水长流
这个作者很懒,什么都没留下…
展开
-
protobuf 2定义string常量
本文介绍如何在protobuf 2中定义string常量原创 2023-08-09 12:00:56 · 1481 阅读 · 0 评论 -
Go 中文字符串 len()返回错误
s := "x张三"size := len(s)//7// 应使用 utf8.RuneCountInString(s)size = utf8.RuneCountInString(s)//3原创 2021-01-26 11:33:03 · 943 阅读 · 0 评论 -
Go gin Get请求参数 支持数组
思路:用string接收,然后通过反序列化成数组即可。controller/service:// str: [1,2]int8Slice := utils.ParamInt8Slice(str)// str: ["a@gmail.com", "b@gmail.com"]stringSlice := utils.ParamStringSlice(str)utils:func ParamInt8Slice(str string) []int8 { res := make([]int8, 0)原创 2021-01-20 11:28:34 · 7382 阅读 · 2 评论 -
go json标签(tag)
go中json序列化使用标签来进行拓展:1、忽略空值:type Person struct { Id int64 `json:"id, omitempty"`}2、忽略字段(不论是否为空值):type Person struct { Id int64 `json:"-"`}3、指定数据类型:type Person struct { Id int64 `json:"id,string"`}...原创 2020-12-24 10:27:31 · 2254 阅读 · 0 评论 -
go reflect.Value获取原始值
go reflect.Value获取原始值type Person struct { Name string}func main() { p := Person{ Name: "James", } // 获取反射 refPerson := reflect.ValueOf(p) // 获取通过反射获取原始值 fmt.Println(refPerson.Interface())}原创 2020-11-06 14:40:49 · 1751 阅读 · 0 评论