I have following struct
type Upload_sgpa_f struct {
Finyear int binding:"required"
Boardlevel string binding:"required"
Useraadhaar int binding:"required"
Excel *multipart.FileHeader form:"excel" binding:"required"
}
var upload_sgpa_f Upload_sgpa_f
upload_sgpa_f.Finyear = nFinyear
upload_sgpa_f.Useraadhaar = nUseraadhaar
upload_sgpa_f.Boardlevel = sBorad
how to assign file to this property upload_sgpa_f.Excel
I have tried following code
// open file handle
fh, err := os.Open(fileInfo.Name())
if err != nil {
fmt.Println(“error opening file”)
return err
}
defer func(fh *os.File) {
err := fh.Close()
if err != nil {
return
}
}(fh)
to assign file to Excel property . It is not working
AFAIK there is no Excel-support in the standard library so you’ll have to provide a bit more context about which library you are using.
BTW: did you know you can use markdown-formatting on this forum? You can make your code look a bit nicer on here. Try it out at https://markdown-it.github.io/
Anyhow, this looks like a recently updated library that can read/write Excel-files locally, without depending on an external service: https://github.com/qax-os/excelize.
Here’s an example to do it with the Gin-framework:
And here’s an example with the Echo-framework (to me it looks more interesting than Gin):
But both of these assume that your client is a web-browser which makes it more complex since you have to do form-handling and stuff.
I’m pretty sure I could hack together a simple http-server and -client without any HTML-stuff in between to just send binary files if that’s ultimately what you want to do? You could even use raw UDP- or TCP-sockets if both client and server or on a local network or if all ports all open but HTTP would be safer for avoiding firewalls etc on the public Internet.