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

csv.go 758 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package util
  2. import (
  3. "bufio"
  4. "encoding/csv"
  5. "io"
  6. "os"
  7. )
  8. func LoadCsvFile(path string, rows *[][]string) {
  9. file, err := os.Open(path)
  10. if err != nil {
  11. panic(err)
  12. }
  13. defer file.Close()
  14. reader := csv.NewReader(bufio.NewReader(file))
  15. reader.LazyQuotes = true
  16. i := 0
  17. for {
  18. line, err := reader.Read()
  19. if err == io.EOF {
  20. break
  21. } else if err != nil {
  22. // log.Fatal(error)
  23. panic(err)
  24. }
  25. *rows = append(*rows, line)
  26. i += 1
  27. }
  28. }
  29. func WriteCsvFile(path string, rows *[][]string) {
  30. file, err := os.Create(path)
  31. if err != nil {
  32. panic(err)
  33. }
  34. defer file.Close()
  35. writer := csv.NewWriter(file)
  36. defer writer.Flush()
  37. i := 0
  38. for _, row := range *rows {
  39. err = writer.Write(row)
  40. if err != nil {
  41. panic(err)
  42. }
  43. i += 1
  44. }
  45. }

基于Casbin的开源AI领域知识库平台

Contributors (1)