Guest User

Untitled

a guest
Nov 19th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "os"
  6.  
  7. "github.com/gocarina/gocsv"
  8. )
  9.  
  10. type Task struct {
  11. TaskType string `json:"task_type" validate:"required" csv:"task_type"`
  12. Description string `json:"description" validate:"required" csv:"description"`
  13. Address string `json:"address" validate:"required" csv:"address"`
  14. AddressExtra string `json:"address_extra" csv:"address_extra"`
  15. City string `json:"city" validate:"required" csv:"city"`
  16. DepState string `json:"dep_state" validate:"required" csv:"dep_state"`
  17. Country string `json:"country" validate:"required" csv:"country"`
  18. Lat float64 `json:"lat" validate:"required" csv:"lat"`
  19. Lon float64 `json:"lon" validate:"required" csv:"lon"`
  20. Meters int `json:"meters" validate:"required" csv:"meters"`
  21. Weight int `json:"weight" validate:"required" csv:"weight"`
  22. }
  23.  
  24. func main() {
  25. tasks := []Task{}
  26.  
  27. tasksFile, err := os.OpenFile("tasks.csv", os.O_RDWR|os.O_CREATE, os.ModePerm)
  28.  
  29. if err != nil {
  30. panic(err)
  31. }
  32. defer tasksFile.Close()
  33.  
  34. if err := gocsv.UnmarshalFile(tasksFile, &tasks); err != nil {
  35. panic(err)
  36. }
  37.  
  38. for _, task := range tasks {
  39. fmt.Println("Hello", task.Address)
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment