Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "github.com/gocarina/gocsv"
- )
- type Task struct {
- TaskType string `json:"task_type" validate:"required" csv:"task_type"`
- Description string `json:"description" validate:"required" csv:"description"`
- Address string `json:"address" validate:"required" csv:"address"`
- AddressExtra string `json:"address_extra" csv:"address_extra"`
- City string `json:"city" validate:"required" csv:"city"`
- DepState string `json:"dep_state" validate:"required" csv:"dep_state"`
- Country string `json:"country" validate:"required" csv:"country"`
- Lat float64 `json:"lat" validate:"required" csv:"lat"`
- Lon float64 `json:"lon" validate:"required" csv:"lon"`
- Meters int `json:"meters" validate:"required" csv:"meters"`
- Weight int `json:"weight" validate:"required" csv:"weight"`
- }
- func main() {
- tasks := []Task{}
- tasksFile, err := os.OpenFile("tasks.csv", os.O_RDWR|os.O_CREATE, os.ModePerm)
- if err != nil {
- panic(err)
- }
- defer tasksFile.Close()
- if err := gocsv.UnmarshalFile(tasksFile, &tasks); err != nil {
- panic(err)
- }
- for _, task := range tasks {
- fmt.Println("Hello", task.Address)
- }
- }
Add Comment
Please, Sign In to add comment