草庐IT

one_at_a_time

全部标签

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我不确定我做错了什么

function - 戈朗 : Stack multiple method calls on one line

Go入门。我正在尝试编写一个函数,该函数将第一个名字命名为首字母,然后将第二个命名为首字母。为什么我不能像下面这样堆叠方法调用?(之所以要在前面放一个.ToLower,是因为.Title只把第一个字母大写,其余的不变)packagemainimport("fmt""strings")funcmain(){firstName:="mElVIn"lastName:="themelvINATor"fmt.Println(nameCap(firstName,lastName))}funcnameCap(s1,s2string)(str1,str2string){s1=strings.ToLow

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(

golang代码组织: where should I put custom error types that are only relevant to one function?

我刚刚开始处理我的第一个golang项目,非常喜欢从函数返回自定义错误类型并在调用代码中使用类型断言来检查特定错误的想法。我发现这个解决方案比总是比较错误消息更清晰。我唯一的问题是:您最好将这些自定义错误类型放在哪里?假设许多自定义错误类型仅由一个实用程序函数使用(返回),它们应该与函数放在同一个包中吗?我应该以某种方式将它们分组吗?或者也许有更好的方法来做这种事情.. 最佳答案 “相同的包裹”是我最初的想法。在某些情况下,将它们放在不同的包中是有意义的,但只有当它们从多个包中的函数中合法地出现“相同的错误”时,并且这些包都不是逻辑

go - Go 中的 time.Sleep 和服务器发送事件 - 意外行为

我正在尝试学习在Go中使用服务器发送的事件(SSE)。这以下是我不理解的行为。我期望(并希望实现):每秒发送一条消息;这将发生五次,然后连接将关闭。实际发生了什么:服务器等待大约5秒然后发送一次发送所有消息,然后关闭连接。如果你能帮助我理解为什么会这样,我将不胜感激。我不清楚我的想法哪里出了问题。每次循环开始时,它应该发送一条消息,休眠然后开始一个新的迭代。谢谢。服务器上的相关代码funcrealTimeHandler(whttp.ResponseWriter,req*http.Request){w.Header().Set("Content-Type","text/event-str

Golang : How to convert int to calculate into time. 持续时间

我是GoLang的新手,目前不知道为什么编译器不接受特定的代码行。我有这个在拨号时创建超时的工作示例:conn,err:=grpc.Dial(*connAddress,grpc.WithInsecure(),grpc.WithBlock(),//willblocktilltheconnectionisavailablegrpc.WithTimeout(100*time.Second))//timesoutafter100seconds现在硬编码的100不太好,所以我想通过标志将其设为命令行变量,如下所示:connTimeout:=flag.Int64("connection-timeo

Go : Same name and content struct in one package , 哪个将被初始化

有一个名为mount的包,它有两个相同的名称和内容结构mount_linxu.gopackagemountimport"fmt"typeMounterstruct{}func(mounter*Mounter)DoMount(pathstring)(bool,error){fmt.Printf("thisislinux")returntrue,nil}mount_mac.gopackagemountimport"fmt"typeMounterstruct{}func(mounter*Mounter)DoMount(pathstring)(bool,error){fmt.Printf("t

go - 如何将以毫秒为单位的字符串时间(hh :mm:ss. xxx)转换为time.Time?

基本上我有这样的时间作为一个字符串:15:56:36.113我想把它转换成time.Time。根据我正在阅读的内容,在使用time.Parse()时我不能使用毫秒。还有其他方法可以将我的字符串转换为time.Time吗? 最佳答案 PackagetimeFormatReferenceTimeAdecimalpointfollowedbyoneormorezerosrepresentsafractionalsecond,printedtothegivennumberofdecimalplaces.Adecimalpointfollow

date - 如何使用 go time 解析外语日期字符串

所以我的问题是:我想这样做:datestring:="19.april2018"parsedDate,err:=time.Parse("2.January2006",datestring)iferr!=nil{fmt.Println(err)}fmt.Println(parsedDate)这段代码完美无缺...但现在我输入的日期字符串不是英语...而是德语。所以四月骗了我。(德语四月=英语四月)。使用datestring:="19.Februar2018"运行此失败:parsingtime"12.februar2018"as"2.January2006":cannotparse"feb

xml - 返回多个节点时 FLWOR 表达式中的错误 "undefined variable at noteLine"

我有一个关于FLWOR循环的非常奇怪的问题,它以一种方式工作,但不能以另一种方式工作。目标是获取任意长度的字符串,并将其分解为每个只能容纳80个字符的XML节点。所以,首先,这很好用:for$noteLinein$noteLineArrwhere$noteLine!=''returnif(fn:string-length(fn:normalize-space($noteLine))WHI{fn:substring(fn:normalize-space($noteLine),1,80)})elseif(fn:string-length(fn:normalize-space($noteLi