Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930
  1. package common
  2. import (
  3. "bufio"
  4. "os"
  5. )
  6. // ReadLines reads all lines from the given path and returns them in a slice of strings.
  7. // If an error occurs, the function will panic.
  8. func ReadLines(path string) []string {
  9. file, err := os.Open(path)
  10. if err != nil {
  11. panic(err)
  12. }
  13. defer func() {
  14. _ = file.Close()
  15. }()
  16. var lines []string
  17. scanner := bufio.NewScanner(file)
  18. for scanner.Scan() {
  19. lines = append(lines, scanner.Text())
  20. }
  21. if scanner.Err() != nil {
  22. panic(scanner.Err())
  23. }
  24. return lines
  25. }