草庐IT

换不起

全部标签

session - 为什么这个 gorilla session 代码不起作用?

我是一个golang菜鸟,所以我正在通过为基于gorilla的网络应用程序设置种子项目来制作我的第一个玩具应用程序。一切顺利,但session代码无法正常工作,hereisthefullcode,这里只是相关的片段:funcgetMyCounter(whttp.ResponseWriter,r*http.Request){session,_:=sessionStore.Get(r,counterSession)ifsession.IsNew{session.Values[myCounter]=0}val:=session.Values[myCounter].(int)log.Print

go - 为什么当我在 go 中添加另一个阻塞线程时信号处理程序不起作用?

我正在尝试构建一个非常简单的TCP服务器/客户端。我希望程序在被ctrl-c中断时可以关闭连接。如果我只在主线程中发送消息或只接收消息,一切正常。这是客户端的代码。packagemainimport("fmt""os""os/signal""syscall""net""bufio""io""time")const(TIMEOUT=10)funcmain(){iflen(os.Args)2{timeout,_=time.ParseDuration(os.Args[2])}iftimeout==0{timeout=time.Duration(TIMEOUT*time.Second)}con

mysql - 全选在 golaong gorm 中不起作用

我正在使用gin框架并尝试使用grom进行crud操作。我正在尝试从MYSQL数据库中获取数据。我有db.go来获取数据库实例,每个表和模型的一些Controller我有一个这样的模型typeCampaignsstruct{IDint`json:"id"form:"id"gorm:"column:CampaignID"`UserIDint`json:"userId"form:"userId"gorm:"column:UserID"`Namestring`json:"name"form:"name"gorm:"column:Name"`StartDatetime.Time`json:"s

linux - 调试器在带有 "Go"插件的 IntelliJ IDEA 中不起作用

我安装的是IntelliJIDEA,go1.4,gopluginforIdea。现在我可以运行GO代码,但不能使用调试器。调试后,我在控制台中看到错误panic:notanIntgoroutine68[running]:go/constant.Int64Val(0x0,0x0,0x2,0xc8200d5180)/usr/local/go/src/go/constant/value.go:236+0x338github.com/derekparker/delve/proc.(*Variable).parseG(0xc8200a6700,0xc8200a6700,0x0,0x0)/opt/

go - 为什么 golang duck typing 在我下面的代码中对我不起作用?

在下面的代码中,我尝试创建模型接口(interface)和API接口(interface)的具体实现:packagemainimport"fmt"/////////typeModelinterface{ID()string}typeAPIinterface{Create(Model)}/////////typeConcreteModelstruct{}func(modelConcreteModel)ID()string{return"123"}func(modelConcreteModel)Name()string{return"aron"}typeConcreteAPIstruct{

google-app-engine - GAE 中 Dockerised Golang Web App 中的 smtp sendmail 不起作用

我在用Go编写的GAE上部署了一个docker化的网络应用程序。支付模块使用stripecheckoutAPI并在成功时触发电子邮件通知。调试时,我观察到以下代码行没有执行。我试过587端口,结果一样。err:=smtp.SendMail("smtp.gmail.com:465",auth,from,[]string{to},[]byte(msg))我在我的本地m/c上有相同的应用程序,此功能适用于它。不过,我没有在我的本地m/c上使用docker。我在“发件人”用户字段中使用与我的GAE帐户相同的用户凭据。这可能是代码失败的原因。或者应该在dockerfile中描述smtp服务身份验

使用验证 V2 Golang 包的正则表达式电话号码不起作用

我在使用github.com/go-validator/validator验证正则表达式时遇到了一些问题,这些电话号码带有此前缀+62、62、0,例如号码+628112blabla,0822blablabla,628796blablabla.我已经在onlineregextester上尝试了我的正则表达式正则表达式没有问题。这里的正则表达式是:(0|\+62|062|62)[0-9]+$但是当我尝试使用我的go工具时,正则表达式不起作用。这是我实现目的的代码:typeParamRequeststruct{PhoneNumberstring`validate:"nonzero,regex

go pprof 在不同的平台上不起作用

我的应用程序在CentOS上运行,当我运行curllocalhost:port/debug/pprof/profile>some.pprof,并运行gotoolpprofsome.pprof,有效。但是当我使用scp将some.pprof文件复制到我的mac并运行gotoolpprofsome.pprof时,它不起作用more,commandtop只显示1行,其中flat和sum都是100%,最后一行是我的应用程序的名称,而不是调用的方法的名称。pprof文件不是跨平台的还是我误用的东西? 最佳答案 正如Adrian所说,二进制文件

json - 将 _id 解码为 id 不起作用

所以我的结构是这样的:typeArticlestruct{IDbson.ObjectId`json:"id"bson:"_id,omitempty"`LangCodestring`json:"langCode"bson:"langCode"`AuthorIdstring`json:"authorId"bson:"authorId"`AuthorNamestring`json:"authorName"bson:"authorName"`ArticleTypeint64`json:"type"bson:"type"`Titlestring`json:"title"bson:"title"`

file - Go http重用似乎在上传文件中不起作用

当我使用我的go(1.8)http库执行正常的GET/POST方法时,它工作正常,如果我尝试使用http库将文件上传到服务器,客户端将创建大量套接字。在我的测试中,文件被切割成碎片上传到5个goroutines,客户端保持250个套接字。我已经添加了deferresp.Body.Close(),这里是关键代码:const(MaxIdleConnsint=40MaxIdleConnsPerHostint=40)transport:=&http.Transport{MaxIdleConns:MaxIdleConns,MaxIdleConnsPerHost:MaxIdleConnsPerHo