MCPcopy Index your code
hub / github.com/derekbanas/Go-Tutorial / getStrings

Function getStrings

webapp/webapp.go:75–96  ·  view source on GitHub ↗

Retreives lines of text from a file

(fileName string)

Source from the content-addressed store, hash-verified

73
74// Retreives lines of text from a file
75func 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
98func newHandler(writer http.ResponseWriter,
99 request *http.Request) {

Callers 1

interactHandlerFunction · 0.85

Calls 1

errorCheckFunction · 0.85

Tested by

no test coverage detected