csv.go 594 B

1234567891011121314151617181920212223242526272829303132333435
  1. package file
  2. import (
  3. "github.com/cnlh/nps/lib/common"
  4. "sort"
  5. "sync"
  6. )
  7. var (
  8. CsvDb *Csv
  9. once sync.Once
  10. )
  11. //init csv from file
  12. func GetCsvDb() *Csv {
  13. once.Do(func() {
  14. CsvDb = NewCsv(common.GetRunPath())
  15. CsvDb.LoadClientFromCsv()
  16. CsvDb.LoadTaskFromCsv()
  17. CsvDb.LoadHostFromCsv()
  18. })
  19. return CsvDb
  20. }
  21. func GetMapKeys(m sync.Map, isSort bool, sortKey, order string) (keys []int) {
  22. if sortKey != "" && isSort {
  23. return sortClientByKey(m, sortKey, order)
  24. }
  25. m.Range(func(key, value interface{}) bool {
  26. keys = append(keys, key.(int))
  27. return true
  28. })
  29. sort.Ints(keys)
  30. return
  31. }