So I want to make a function for download a file in golang using this method below, I build this golang project into C .dll using
go build -buildmode=c-shared -o patcher.dll main.go
I managed to use this function on my C# application to get progress of file download, my current function (DownloadFfile) works if I just print it directly using DownloadFile() , however i want to get the progress asynchronously on my C# application , but i can't get the value directly, so I think I need to return integer of progress from my golang application but if I do that the function just go 1 times (the last result of progress)
The question is how to make my go func DownloadFile being called 1 times on my C# application but I can still keep track the progress ? Any help will be appreciated , thank you.
func DownloadFile(){
// create client
client := grab.NewClient()
req, _ := grab.NewRequest(".", "http://www.golang-book.com/public/pdf/gobook.pdf")
// start download
fmt.Printf("Downloading %v...
", req.URL())
resp := client.Do(req)
fmt.Printf(" %v
", resp.HTTPResponse.Status)
// start UI loop
t := time.NewTicker(500 * time.Millisecond)
defer t.Stop()
Loop:
for {
select {
case <-t.C:
fmt.Printf("%.2f%",
//resp.BytesComplete(),
//resp.Size,
100*resp.Progress())
case <-resp.Done:
// download is complete
break Loop
}
}
// check for errors
if err := resp.Err(); err != nil {
fmt.Fprintf(os.Stderr, "Download failed: %v
", err)
os.Exit(1)
}
// fmt.Printf("Download saved to ./%v
", resp.Filename)
// Output:
// Downloading http://www.golang-book.com/public/pdf/gobook.pdf...
// 200 OK
// transferred 42970 / 2893557 bytes (1.49%)
// transferred 1207474 / 2893557 bytes (41.73%)
// transferred 2758210 / 2893557 bytes (95.32%)
// Download saved to ./gobook.pdf
}