Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Created January 4, 2022 18:54
Show Gist options
  • Save jeffotoni/3a4df93d69968c51bda7b393350ea764 to your computer and use it in GitHub Desktop.
Save jeffotoni/3a4df93d69968c51bda7b393350ea764 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/csv"
"fmt"
"os"
)
type empData struct {
Name string
Age string
City string
}
func main() {
csvFile, err := os.Open("funcionarios.csv")
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened CSV file")
defer csvFile.Close()
csvLines, err := csv.NewReader(csvFile).ReadAll()
if err != nil {
fmt.Println(err)
}
for _, line := range csvLines {
emp := empData{
Name: line[0],
Age: line[1],
City: line[2],
}
fmt.Println(emp.Name + " " + emp.Age + " " + emp.City)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment