Exemplo n.º 1
0
func csv2JsonServer(w http.ResponseWriter, req *http.Request) {
	jsonData, err := csv2json.Convert(req.Body, columns)
	defer req.Body.Close()
	if err != nil {
		http.Error(w, "Could not convert csv to json", 503)
	}
	w.Write(jsonData)
}
func main() {
	flag.Parse()
	if infile == "" {
		log.Fatal("Input file required")
	}
	f, err := os.Open(infile)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	jsonData, err := csv2json.Convert(f, columns)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(jsonData))
}