Retreives lines of text from a file
(fileName string)
| 73 | |
| 74 | // Retreives lines of text from a file |
| 75 | func getStrings(fileName string) []string { |
| 76 | var lines []string |
| 77 | |
| 78 | // Try to open the file (It must exist) |
| 79 | file, err := os.Open(fileName) |
| 80 | if os.IsNotExist(err) { |
| 81 | return nil |
| 82 | } |
| 83 | errorCheck(err) |
| 84 | // Close file when the function ends |
| 85 | defer file.Close() |
| 86 | |
| 87 | // Read lines of text and save to lines |
| 88 | scanner := bufio.NewScanner(file) |
| 89 | for scanner.Scan() { |
| 90 | lines = append(lines, scanner.Text()) |
| 91 | } |
| 92 | errorCheck(scanner.Err()) |
| 93 | |
| 94 | // Return the text |
| 95 | return lines |
| 96 | } |
| 97 | |
| 98 | func newHandler(writer http.ResponseWriter, |
| 99 | request *http.Request) { |
no test coverage detected