I have the ECHO framework which should return the file on request, and it's working well
func IniExport(c echo.Context) error{
cfg := ini.Empty()
if section, err := cfg.NewSection("test_section"); err != nil {
return c.JSON(http.StatusInternalServerError, "Problems with generation of export file.")
}
if key, err := cfg.Section("test_section").NewKey("name", "value"); err != nil {
return c.JSON(http.StatusInternalServerError, "Problems with generation of export file.")
}
cfg.SaveTo("export.ini")
defer os.Remove("export.ini")
return c.Attachment("export.ini", "export.ini")
}
But question, is it possible to not create physical file export.ini and after do not remove it? Possible to return content on the fly somehow? Thanks
I think you need Send Blob.
You can use the WriteTo function to write the
cfg
content to theio.Writer
first and then those contents can be used instead ofdata
(in the previous code example. Also make sure to change the content type totext/plain
)