You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
939 B

  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "strings"
  6. mgo "gopkg.in/mgo.v2"
  7. )
  8. func readDataset(path string, lineSeparation string, valueSeparation string) [][]string {
  9. var dataset [][]string
  10. b, err := ioutil.ReadFile(path)
  11. check(err)
  12. str := string(b)
  13. str = strings.Replace(str, "\r", "", -1)
  14. lines := strings.Split(str, lineSeparation)
  15. for _, v1 := range lines {
  16. params := strings.Split(v1, valueSeparation)
  17. var datasetLine []string
  18. for _, v2 := range params {
  19. datasetLine = append(datasetLine, v2)
  20. }
  21. dataset = append(dataset, datasetLine)
  22. }
  23. return dataset
  24. }
  25. func getItemsFromDataset(dataset [][]string) []ItemModel {
  26. var items []ItemModel
  27. for _, v := range dataset {
  28. var newItem ItemModel
  29. newItem.ID = v[0]
  30. items = append(items, newItem)
  31. }
  32. return items
  33. }
  34. func datasetToMongodbIfNotExist(c *mgo.Collection, items []ItemModel) {
  35. fmt.Println(items)
  36. for _, item := range items {
  37. saveItem(c, item)
  38. }
  39. }