草庐IT

execution-time

全部标签

postgresql - 连接 : connection timed out

我已经使用gosql包成功连接到Postgres数据库:...db,err:=sql.Open("postgres",connStr)然后我使用返回的数据库执行(长时间运行的)查询:rows,err:=db.Query(...)我得到了错误:dialtcpxx.xxx.xxx.xx:5432:connect:connectiontimedout我有几个问题:为什么连接超时?我能做些什么来防止它超时吗? 最佳答案 sql.Open()mayjustvalidateitsargumentswithoutcreatingaconnecti

go - 为什么 "gofmt -d"给出 "computing diff: exec: "diff": executable file not found in %PATH%"error on windows?

我想看看我在golang文件中犯了哪些错误。为了弄清楚,我发出这样的命令:gofmt-dmyfile.go根据gofmt--help手册,它应该列出文件的当前版本和所需版本的差异。取而代之的是,它会生成此错误消息:computingdiff:exec:"diff":executablefilenotfoundin%PATH%如何解决这个问题? 最佳答案 gofmt工具假设系统已经安装了可用的diff。遗憾的是,此工具不是标准Windows安装的一部分,因此您需要手动添加它。对于我们大多数人来说,最简单的方法是添加我们计算机上已有的d

go - 如何在 DataStore 中存储 *time.Time 类型的结构字段的当前时间?

这个问题在这里已经有了答案:Assignvaluereturnedfromfunctiontopointer(1个回答)关闭3年前。根据我的要求,我创建了一个结构为-typeMyRulestruct{CreatedAttime.Time`json:"createdAt"datastore:"createdAt,noindex"`UpdatedAt*time.Time`json:"updatedAt"datastore:"updatedAt,noindex"`}对于createdAt字段,我可以将当​​前时间存储为-MyRule.CreatedAt=time.Now()但是,将当前时间存

go - 为什么我的程序在添加 time.sleep 时挂起?

我正在尝试对我的程序进行测试,该程序将在设定的时间间隔内保存到磁盘。我的问题是当我添加time.Sleep测试时,无论持续时间如何,程序都会挂起。我的预期行为是我允许它休眠,并且go例程应该在后台运行并保存到磁盘上。这是作为测试中的goroutine运行的相关函数。节点服务.gofuncrunRegistryBackup(reg*NodeRegistry,intervalint,killchanchanbool){log.SetPrefix("[RegistryBackup]\t")log.Printf("Intializingbackupevery%dseconds",interva

go - 错误 "protoc-gen-go: program not found or is not executable"

我正在尝试使用Go构建示例应用程序gRPC,但我无法使用“协议(protocol)”生成代码我已经使用以下方法安装了所需的库和Go包:goget-ugoogle.golang.org/grpcgoget-ugithub.com/golang/protobuf/protoc-gen-go我也试过设置路径,但没有成功。示例“原型(prototype)”文件:syntax="proto3";packagegreet;optiongo_package="greetpb";serviceGreetService{}错误信息:"protoc-gen-go:programnotfoundorisno

linux - Go 导致 OpenGL 与 time.Tick 但不是 time.After 发生段错误

我有以下两个文件:bridge.go:packagecube//#cgoLDFLAGS:-lGL-lGLEW-lglfw//#include//intinit(GLFWwindow**);//voidrender(GLFWwindow*);import"C"import("fmt""time")funcInit(){varwindow*_Ctype_GLFWwindowwindowWat:=(*[0]byte)(window)fmt.Printf("Callinginit\n")ifC.init(&windowWat)!=1{return}window=(*_Ctype_GLFWwin

time - 戈朗 : throttle (time delay) function is not working in goroutine (works fine in main thread)

所以我正在编写一个实用程序来查询工作中的API,它们将每10秒限制为20次调用。很简单,我会将我的通话时间限制在自上次通话后至少0.5秒。在我尝试使用goroutine之前,我的Throttle实用程序运行良好。现在我正在使用结构/方法组合:func(c*CTKAPI)Throttle(){ifc.Debug{fmt.Println("\t\t\tEnteringThrottle()")}for{//incasesomethingelsemakesacallwhilewe'resleeping,weneedtore-checkift:=time.Now().Sub(c.LastCall

go - 如何遍历 go time.Tick channel ?

我在使用time.Tick时遇到困难。我希望这段代码打印“hi”10次,然后在1秒后退出,但它挂起了:ticker:=time.NewTicker(100*time.Millisecond)time.AfterFunc(time.Second,func(){ticker.Stop()})for_=rangeticker.C{gofmt.Println("hi")}https://play.golang.org/p/1p6-ViSvma查看source,我看到调用Stop()时channel没有关闭。在那种情况下,遍历代码channel的惯用方法是什么? 最佳

datetime - Golang - 结构 : time. 时间

这个问题在这里已经有了答案:Multiplevaluesinsingle-valuecontext(6个答案)关闭6年前。我正在尝试将一个值转换为具有时间类型的结构。时间。值为:t:=time.Now()format:="2006-01-0215:04:05"然后我尝试将其放入结构中:response.SetAppData[0].LiveDate=time.Parse(format,t.String())但是我得到的错误是:controllers/apps.go:1085:multiple-valuetime.Parse()insingle-valuecontext我不确定我做错了什么

go - 使用 time.AfterFunc 在 golang 中按时间间隔执行重复性任务,只是一个示例

我只想在Go中做重复的后台任务,使用time.AfterFunc,但似乎逻辑有问题。输出只是:间隔调用间隔调用但如果一切正常,至少要调用该函数5次。packagemainimport("fmt""time""os""os/signal")typeTimerstruct{Queuechan*TimeCall}funcNewTimer(lint)*Timer{timer:=new(Timer)timer.Queue=make(chan*TimeCall,l)returntimer}typeTimeCallstruct{timer*time.Timercallbackfunc()}func(