我对 Golang 有点陌生,正在尝试开发一个将图像异步上传到 imgur 的程序。但是我的代码遇到了一些困难。
所以这是我的任务;
func uploadT(url string,c chan string, d chan string) {
var subtask string
subtask=upload(url)
var status string
var url string
if subtask!=""{
status = "Success!"
url =subtask
} else {
status = "Failed!"
url =subtask
}
c<-url
d<-status
}
这是我用于异步上传的 POST 请求循环;
c:=make(chan string, len(js.Urls))
d:=make(chan string, len(js.Urls))
wg:=sync.WaitGroup{}
for i := range js.Urls{
wg.Add(1)
go uploadTask(js.Urls[i],c,d)
//Below commented out code is slowing down the routine therefore, I commented out.
//Needs to be working as well, however, it can work if I put this on task as well. I think I'm kinda confused with this one as well
//pol=append(pol,retro{Url:<-c,Status:<-d})
}
<-c
<-d
wg.Done()
FinishedTime := time.Now().UTC().Format(time.RFC3339)
qwe=append(qwe,outputURLs{
jobID:jobID,
retro:pol,
CreateTime: CreateTime,
FinishedTime: FinishedTime,
})
fmt.Println(jobID)
所以我觉得我的渠道和套路不行。它确实在上传任务之前打印出 jobID。而且上传对于异步上传来说似乎太慢了。
我知道代码有点乱,对此感到抱歉。非常感谢任何帮助!提前致谢!
Cats萌萌
翻阅古今
相关分类