-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhelper.go
More file actions
37 lines (31 loc) · 687 Bytes
/
helper.go
File metadata and controls
37 lines (31 loc) · 687 Bytes
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
package main
import (
"bufio"
"math/rand"
"os"
)
func randomString(n int) string {
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
b := make([]rune, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}
func readFile(filename string) ([]string, error) {
var ret []string
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
scanner := bufio.NewScanner(file)
// optionally, resize scanner's capacity for lines over 64K, see next example
for scanner.Scan() {
ret = append(ret, scanner.Text())
}
if err := scanner.Err(); err != nil {
return nil, err
}
return ret, nil
}