From 1b3bfbf1dff2ef8e85e45fa3ea95eaa7d93fe4aa Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Wed, 3 Aug 2016 16:19:39 +1000 Subject: [PATCH] Added CSV output functionality. --- common.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/common.go b/common.go index 5a36e1c8..33f32374 100644 --- a/common.go +++ b/common.go @@ -7,6 +7,7 @@ import ( "crypto/sha256" "crypto/sha512" "encoding/base64" + "encoding/csv" "encoding/hex" "encoding/json" "errors" @@ -17,6 +18,7 @@ import ( "math" "net/http" "net/url" + "os" "strconv" "strings" ) @@ -283,8 +285,26 @@ func ExtractHost(address string) string { } return host } + func ExtractPort(host string) int { portStr := SplitStrings(host, ":")[1] port, _ := strconv.Atoi(portStr) return port } + +func OutputCSV(path string, data [][]string) error { + file, err := os.Create(path) + if err != nil { + return err + } + + writer := csv.NewWriter(file) + + err = writer.WriteAll(data) + if err != nil { + return err + } + + defer writer.Flush() + return nil +}