草庐IT

request-timed-out

全部标签

go - 将 "net/http"上的 *Request 传递给 Golang 函数

是否可以将请求值传递给另一个函数?import"net/http"funcmain(){http.HandleFunc("saySomething",Say)}funcSay(responseWhttp.ResponseWriter,request*http.Request){name:=getName(request)//passingrequestvaluetoanotherfunction}funcgetName(requestsomeType)string{request.ParseForm()returnrequest.Form.Get("name")}

select - 从非 chan 类型 time.Duration 接收

在thistutorial提供以下示例:funcLongRunningHandler(ctxcontext.Context)string{deadline,_:=ctx.Deadline()for{select{case当我编译此代码时出现以下错误:invalidoperation:示例中的代码有什么问题? 最佳答案 用于从channel接收,为此既不time.Until或Truncate返回一个channel。在这种情况下,错误消息是在识别问题,但并没有真正说明实际需要采取哪些不同的措施。go确实提供了一些返回channel的时间

datetime - 一次 time.Parse 错误,我做错了什么?

我遇到了关于使用时间包在golang中解析日期字符串的最奇怪的问题。错误:parsingtime"07-20-2018"as"2006-01-02":cannotparse"0-2018"as"2006"代码块:log.Println(datestring)//07-20-2018date,err:=time.Parse("2006-01-02",datestring)log.Println(err)//parsingtime"07-20-2018"as"2006-01-02":cannotparse"0-2018"as"2006"log.Println(date)//parsingt

http - 从 net/http.Request.RemoteAddr 获取 IP 地址最干净的方法是什么

Golangnet/http库提供了一个Requeststruct,这是运行服务器时返回的对象。该结构包括RemoteAddr:string。这包含远程(客户端)IP地址和客户端端口号。当然可以是IPv4或IPv6。看到的IPv6示例值(当客户端在本地主机上时)是:"[::1]:53947"一个IPv4例子是:"127.0.0.1:54572"是否有库函数将它们分解为主机和端口,或者是否有必要使用字符串操作? 最佳答案 我认为您正在寻找net.SplitHostPort:funcmain(){host,_,_:=net.SplitH

Go time.Parse() 得到 “month out of range” 错误

我是Go的新手,我正在解析一个nginx时间格式字符串。你可以在这里查看我的代码:packagemainimport( "time" "log" "fmt")funcmain(){ //nginxtimeformat nginx_time:="03/Apr/2017:08:29:05+0800" t,err:=time.Parse("02/Jan/2016:15:04:05MST",nginx_time) iferr!=nil{ log.Fatal(err) } fmt.Println(t.Format("2006-01-0215:04:05"))}我收到以下错误:GOROOT=/u

go - 我收到错误 fatal error : runtime: out of memory while downloading video using 'go-ipfs-api'

我使用go-ipfs-api从ipfs下载了一个大文件,web访问下载。我收到一个fatalerror:runtime:outofmemory.如何修改我的代码?funcmain(){http.HandleFunc("/",download)http.ListenAndServe(":8080",nil)}funcdownload(whttp.ResponseWriter,r*http.Request){client:=shell.NewShell("http://127.0.0.1:5001")fd,err:=client.Cat("QmTcj7SfRf4vnLnCqnxMT7kut

parsing - 允许多次读取 http.Request.Body 的正确方法是什么

我想多次访问http.Request的Body。第一次发生在我的身份验证中间件中,它使用它来重新创建sha256签名。第二次发生在稍后,我将其解析为JSON以便在我的数据库中使用。我知道您不能多次从io.Reader(或本例中的io.ReadCloser)读取数据。我找到了一个answertoanotherquestion有一个解决方案:Whenyoufirstreadthebody,youhavetostoreitsoonceyou'redonewithit,youcansetanewio.ReadCloserastherequestbodyconstructedfromtheori

http - Go 中 'net/http' 中的 request.FormValue 为空

我正在尝试使用端点创建一个简单的http服务,以在Go中将文件下载到本地系统。该链接位于?uri标记中,但是当我想要获取它时,我收到一个空字符串。我试图解析我的请求的形式,但没有帮助。这是我的代码:funcmain(){http.HandleFunc("/download",DownloadHandler)log.Fatal(http.ListenAndServe(":8080",nil))}funcDownloadHandler(writerhttp.ResponseWriter,request*http.Request){prsErr:=request.ParseForm()ifp

go - 我如何从 time.Now() 函数中获取分钟和小时

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭3年前。Improvethisquestion我正在做一个检查程序,我需要以分钟为单位的实时时间,比如如果是10:00,我应该有600分钟我尝试使用time.Now()函数以及.Hour和.Minute并且它有效但遗憾的是当涉及到ParseDuration来获取小时数时我得到这些错误:go:91:4:赋值不匹配:1个变量但time.ParseD

time - 两个持续时间的乘积在 Golang 变量中为零

在下面的Golang代码中,两个持续时间的乘积在变量“delay”中为零很奇怪,但是当不通过任何变量直接打印乘积时,输出符合预期。任何人都可以解释这个吗?funcStartCleanTask(){gofunc(){delay:=cfg.Config.Timeout*time.Secondfor{fmt.Println("Gocleantask:",delay,cfg.Config.Timeout*time.Second)select{case输出是:Gocleantask:05m0s更新:我还尝试运行以下代码,它运行良好。packagemainimport"fmt"import"tim