123456789101112131415161718192021222324252627282930 |
- package common
-
- import (
- "bufio"
- "os"
- )
-
- // ReadLines reads all lines from the given path and returns them in a slice of strings.
- // If an error occurs, the function will panic.
- func ReadLines(path string) []string {
- file, err := os.Open(path)
- if err != nil {
- panic(err)
- }
- defer func() {
- _ = file.Close()
- }()
-
- var lines []string
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- lines = append(lines, scanner.Text())
- }
-
- if scanner.Err() != nil {
- panic(scanner.Err())
- }
-
- return lines
- }
|