Created
September 5, 2012 22:24
-
-
Save ninnemana/3646325 to your computer and use it in GitHub Desktop.
CSV Export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prices, _ := pricing.Get(r) | |
var buf bytes.Buffer | |
buf.WriteString("CURT Part ID,Customer Part ID, Price, Sale Start, Sale End\n") | |
for i := 0; i < len(prices)-1; i++ { | |
price := prices[i] | |
var priceBuf bytes.Buffer | |
priceBuf.WriteString(strconv.Itoa(price.PartID)) | |
priceBuf.WriteByte(',') | |
priceBuf.WriteString(strconv.Itoa(price.CustPartID)) | |
priceBuf.WriteByte(',') | |
priceBuf.WriteString(strconv.FormatFloat(price.Price, 'f', 2, 64)) | |
priceBuf.WriteByte(',') | |
if price.IsSale == 1 { | |
priceBuf.WriteString(price.Sale_start.(string)) | |
priceBuf.WriteByte(',') | |
priceBuf.WriteString(price.Sale_end.(string)) | |
priceBuf.WriteByte(',') | |
} | |
priceBuf.WriteString("\n") | |
buf.Write(priceBuf.Bytes()) | |
} | |
w.Header().Set("Content-Type", "text/csv") | |
w.Header().Set("Content-Disposition", "attachement;filename=data.csv") | |
w.Write(buf.Bytes()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment