"github.com/gocarina/gocsv"
content, err := gocsv.MarshalString(&result)
common.CsvDownload(ctx, "列表导出", content)
func CsvDownload(ctx iris.Context, filename, content string) {
ctx.Header("Content-Type", "application/csv")
ctx.Header("Content-Disposition", fmt.Sprintf("attachment;filename=%s.csv", filename))
ctx.WriteString("\xEF\xBB\xBF") // 写入UTF-8 BOM,防止中文乱码
ctx.WriteString(content)
}