-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (46 loc) · 1.05 KB
/
main.go
File metadata and controls
58 lines (46 loc) · 1.05 KB
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
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"flag"
"interview/src/generator"
"interview/src/reader"
"log"
"os"
"runtime/pprof"
)
const (
input_file = "data.txt"
output_file = "data.csv"
alphabet = "abcdefghijklmnopqrstuvwxyz"
line_length = 7
total_lines = 10_000_000
)
func main() {
// taken from https://go.dev/blog/pprof
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
db := reader.Database{
Username: "postgres",
Password: "postgres",
Host: "localhost",
Name: "interview",
Port: 5433,
}
conn := reader.ConnectToDB(db)
//clear the table
_, err := conn.Exec(context.Background(), "truncate table tokens")
if err != nil {
panic("Could not clear")
}
defer conn.Close(context.Background())
generator.GenerateRandomStrings(input_file, []byte(alphabet), line_length, total_lines)
reader.Read(input_file, output_file, conn)
}