Added option to download items from list

This commit is contained in:
Pijus Kamandulis
2020-01-24 19:02:50 +02:00
parent 1782a2f12b
commit 6f8ab8a277
7 changed files with 99 additions and 13 deletions
+21
View File
@@ -1,10 +1,13 @@
package utils
import (
"bufio"
"io/ioutil"
"os"
)
type delegateString func(string)
// CheckIfExists - Checks if file or directory exists
func CheckIfExists(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
@@ -30,3 +33,21 @@ func ReadFileToString(path string) string {
return string(content)
}
// ReadFileLineByLine - Reads file line by line and calls delegate
func ReadFileLineByLine(path string, delegate delegateString) {
file, err := os.Open(path)
if err != nil {
panic(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
delegate(scanner.Text())
}
if err := scanner.Err(); err != nil {
panic(err)
}
}