Ejemplo n.º 1
0
func main() {
	data := file.ReadCSV("table.csv")

	tpl, err := template.ParseFiles("tpl.gohtml")
	if err != nil {
		log.Fatalln(err)
	}

	http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
		err = tpl.Execute(res, data)
		if err != nil {
			log.Fatalln(err)
		}
	})

	http.ListenAndServe(":9000", nil)
}
Ejemplo n.º 2
0
/*
Create a program which can read a csv file and write it as a JSON file.
*/
func csvToJSON(csvFile, jsonFile string) {
	//read CSV file
	data := file.ReadCSV(csvFile)

	//do stuff with data to get into struct
	var slice []Pasta
	for _, each := range data {
		var obj Pasta
		obj.Noodle = each[0]
		obj.Sauce = each[1]
		obj.Cheese = each[2]
		obj.Meat = each[3]
		slice = append(slice, obj)
	}

	//write to JSON file
	myJsonBytes, _ := json.Marshal(slice)
	file.WriteNew(jsonFile, string(myJsonBytes))
}