summaryrefslogtreecommitdiff
path: root/utils/other_utils.go
blob: 13c6c1591863cc66c3a25cb4d159b1c05111624e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package utils

import (
	"bufio"
	_ "encoding/json"
	_ "fmt"
	"io"
	_ "net"
	_ "net/http"
	"os"
	_ "strconv"
	"strings"
)

func RetrieveLines(pool chan string, filename string) {
	f, err := os.Open(filename)
	if err != nil {
		panic(err)
	}
	//fmt.Println("reading file ...")
	reader := bufio.NewReader(f)
	for {
		s, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		s = strings.Trim(s, "\n")
		pool <- s
	}
	close(pool)
}

func RetrieveLinesToSlice(filename string) []string {
	results := []string{}
	f, err := os.Open(filename)
	if err != nil {
		panic(err)
	}
	reader := bufio.NewReader(f)
	for {
		s, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		s = strings.Trim(s, "\n")
		results = append(results, s)
	}
	return results
}