go
jiuweiC
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Cgo go slice 转c数组
cgo 数组转换原创 2023-01-06 11:55:57 · 551 阅读 · 0 评论 -
cgo 调试
cgo 的调试原创 2023-01-04 15:02:03 · 861 阅读 · 0 评论 -
gomonkey
1.mock 函数1.mock 方法 (interface)type Student struct {}func (s Student) Interesting(prodName string) bool{ return true}func testFunc(prodName string) bool{ st := &Student{} result := st.Interesting(prodName) if false == result { fmt.Println("S原创 2020-12-01 18:15:00 · 556 阅读 · 0 评论 -
Go flag参数
指定参数func main() { var data1 string var data2 int var data3 bool flag.StringVar(&data1, "data1", "data1", "data1") flag.IntVar(&data2, "data2", 0, "data2") flag.BoolVar(&data3, "data3", false, "data3") flag.Parse() fmt.Printf(" %v %v %v原创 2020-11-26 19:52:41 · 187 阅读 · 0 评论 -
go build打包
1、Mac下编译Linux, Windows平台的64位可执行程序:$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build test.go$ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build test.go2、Linux下编译Mac, Windows平台的64位可执行程序:$ CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build test.go$ CGO_ENABLE原创 2020-11-13 19:33:20 · 1455 阅读 · 0 评论 -
Golang test
执行覆盖率检测go test -coverprofile=c.out将结果文件转htmlgo tool cover -html=c.out原创 2020-11-11 15:00:55 · 150 阅读 · 0 评论 -
go sqlx
文档:https://jmoiron.github.io/sqlx/demo : https://github.com/jmoiron/sqlx原创 2020-09-03 21:22:19 · 166 阅读 · 0 评论 -
swaggo无法生成swagger.json
swaggo无法生成swagger.jsonswaggo 的包管理还不支持gomod,也就是说需要gopath解决方案 export GOPATH=/Users/anker/Documents/go_work //设置gopath export GO111MODULE=off //关闭gomod开关 swaggo -s ./main.go -o ./conf原创 2020-05-28 17:37:31 · 1166 阅读 · 0 评论 -
Golang字符与字符串
一、字符golang的字符有两种1.byte uint8,代表ASCII的一个字符2.rune int32 ,是UTF-8字符,处理符合字符(汉语)的时需要用到所以在go中,字符的本质是一个整数。1.默认处理 char := 'c' char1 := '你' fmt.Printf("%T,%v ,%c\n", char, char, char) fmt.Printf("%T,%v ,%c\n", char1, char1, char1) //int32,99 ,c //int32,原创 2020-05-24 19:34:40 · 544 阅读 · 0 评论 -
go is shadowed during return
func test( req *Req) (diff string, err error) { if reqParam != nil && len(reqParam.UserID) > 0 { diff, err := compareMemo(reqParam) if err != nil { return }}因为上面diff, err是新的变量不是返回值列表里面变量无返回值的return,会把返回值列表中的retI和retF返回出去,而不是新的作用域里的原创 2020-05-12 12:19:46 · 312 阅读 · 0 评论 -
Golang 发送html Gmail邮件
一、创建Gmail应用专用密码https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637238169477945712-2824207204&rd=11.开启两步验证2.创建应用专用密码https://accounts.google.com/signin/v2/sl...原创 2020-04-30 16:26:40 · 2725 阅读 · 2 评论 -
Proto GO使用教程
一、文件内构成syntax = "proto3"; //proto版本package api; //生成文件的包名//数据结构message Persion { int64 name = 1; int64 age = 3;}二、命令解析protoc --go_out=. *.proto–go_out输出方式 以Go文件的方式输出–go_out=. .pr...原创 2020-04-07 00:59:10 · 1090 阅读 · 0 评论 -
go mod verifying 410 gone
使用go version go1.13.8 更新的依赖是私有仓库会如下报错verifying 410 [地址] gone解决办法:export GO111MODULE=onexport GOPROXY=directexport GOSUMDB=off原创 2020-02-18 23:11:34 · 2092 阅读 · 0 评论 -
Gorm 问题汇总
Gorm 问题汇总官方文档1.CreatedAt,UpdatedAt,DeletedAt 自动赋值基本模型定义gorm.Model,包括字段ID,CreatedAt,UpdatedAt,DeletedAt`,你可以将它嵌入你的模型,或者只写你想要的字段2.使用.first查询时,unsupported destination, should be slice or struct错误...原创 2019-08-29 13:30:38 · 1349 阅读 · 0 评论 -
golan无法再test下debug
报错: could not launch process: exec: "lldb-server": executable file not found in $PATH解决办法:原创 2018-08-15 16:19:56 · 493 阅读 · 0 评论 -
路径配置
命令行修改GOPATHexport GOPATH=/Users/anker/Documents/workspace/workspace_go/omc/backend/go/src环境变量查询echo $PATH原创 2018-09-05 18:57:36 · 1304 阅读 · 0 评论 -
mac go安装配置
---基于官网包下载安装由于mac原本已经安装过官网go,所有直接通过brew的方式安装,goroot还是原来的路径。所以仍然选择下载官网go包,该包安装后会自动配好环境。 介绍mac下的安装和使用教程安装包下载地址(下面3个都可以): https://studygolang.com/dl https://golang.google.cn/dl/ https://golang.o...原创 2018-09-17 15:30:35 · 449 阅读 · 0 评论 -
beego问题总结
beego问题总结问题 1:gob: name not registered for interface *adminDto.UserAuthority{}原因:使用beego 存session,存入session的结构体必须提前注册到gob里面c.SetSession(controllers.HttpSessionUserAuthority, auth)解决方案:在main...原创 2018-09-21 11:46:08 · 775 阅读 · 0 评论 -
dep 包更新
1.运行位置,必须位于gopath下,否则会报错如下root project import: dep does not currently support using GOPATH/src as the project root即不能位于Gopath /src更新依赖2.设置gopath (临时gapath)直接在命令行添加 export GOPATH=/usr/loca...原创 2018-11-01 17:40:27 · 1104 阅读 · 0 评论 -
grom err整理
一、更新异常user.Name = "jinzhu 2"user.Age = 100db.Save(&user)该Save将包括执行更新SQL时的所有字段,即使它没有更改,// 使用`struct`更新多个属性,只会更新这些更改的和非空白字段db.Model(&user).Updates(User{Name: "hello", Age: 18})//// ...原创 2019-02-28 16:10:09 · 367 阅读 · 0 评论 -
Go interface处理不同model
func SearchVP(req *dto.VoicePackageReq) ([]*models.VoicePackage, int, error) { query := []baseDto.Query{ {Field: "name", Value: req.Name, Type: db.QUERY_LIKE}, {Field: "product_code", Value: re...原创 2019-03-06 14:22:05 · 565 阅读 · 0 评论 -
GO Mod使用教程
GO Mod使用教程##一、管理依赖###1.初始化项目 my_projectcd my_projectgo mod init my_project即会在my_project目录下生成go.mod#2.下载依赖go mod download下载依赖并在my_project下生成go.lock##二、ide支持目前介绍goland1.在preferences->go...原创 2019-04-23 18:52:49 · 12836 阅读 · 2 评论 -
Go-可变参数
可变参数一、使用场景避免创建仅作传入参数用的临时切片当参数数量未知传达你希望增加可读性的意图例func test(items ...string){}func test1(items ...string){}func main(){ a:=getA() b:=getB() //可变参数 test(a,b) //切片参数略显累赘 test([]stri...原创 2019-06-13 10:20:06 · 295 阅读 · 0 评论 -
MongoDB的goland使用
MongoDB的goland使用文档:https://godoc.org/go.mongodb.org/mongo-driver/bson/primitive一、string和ObjectID的转换ObjectID->stringfunc (ObjectID) Hexfunc (id ObjectID) Hex() stringstring->ObjectIDfunc ...原创 2019-06-04 10:24:35 · 1114 阅读 · 0 评论 -
Go windows安装 (zip)
一、下载地址 https://studygolang.com/dl选择window系统 archive类型二、环境安装1.将下载压缩包解压到你想的路径,2.打开环境变量3.配置GOROOT4.配置go/bin到环境变量path下...原创 2019-07-05 00:00:43 · 2621 阅读 · 0 评论 -
flag redefined: graceful
glide vender 多个无法识别,修改为唯一原创 2018-04-19 14:15:55 · 2441 阅读 · 1 评论
分享