Join webbapp core modules into single package
This commit is contained in:
36
internal/webapp/ReadLines.go
Normal file
36
internal/webapp/ReadLines.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package webapp
|
||||
|
||||
import (
|
||||
"aleesa-webapp-go/internal/log"
|
||||
"bufio"
|
||||
"os"
|
||||
)
|
||||
|
||||
// ReadLines читает даденный файл построчно в массив строк.
|
||||
func ReadLines(path string) ([]string, error) {
|
||||
file, err := os.Open(path)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer func(file *os.File) {
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Unable to close file %s:%s", path, err)
|
||||
}
|
||||
}(file)
|
||||
|
||||
var (
|
||||
lines []string
|
||||
scanner = bufio.NewScanner(file)
|
||||
)
|
||||
|
||||
for scanner.Scan() {
|
||||
lines = append(lines, scanner.Text())
|
||||
}
|
||||
|
||||
return lines, scanner.Err()
|
||||
}
|
||||
|
||||
/* vim: set ft=go noet ai ts=4 sw=4 sts=4: */
|
||||
Reference in New Issue
Block a user