Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
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.

40 lines
728 B

  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func main() {
  7. hdr := []string{"empid", "employee", "address", "hours worked",
  8. "hourly rate", "manager"}
  9. result := csvHdrCol(hdr)
  10. fmt.Println("Result:")
  11. fmt.Println(result)
  12. fmt.Println()
  13. hdr2 := []string{"employee", "empid", "hours worked", "address",
  14. "manager", "hourly rate"}
  15. result2 := csvHdrCol(hdr2)
  16. fmt.Println("Result2:")
  17. fmt.Println(result2)
  18. fmt.Println()
  19. }
  20. func csvHdrCol(hdr []string) map[int]string {
  21. csvIdxToCol := make(map[int]string)
  22. for i, v := range hdr {
  23. v = strings.TrimSpace(v)
  24. switch strings.ToLower(v) {
  25. case "employee", "hours worked", "hourly rate":
  26. csvIdxToCol[i] = v
  27. }
  28. }
  29. return csvIdxToCol
  30. }