Skip to content

Commit 9b52768

Browse files
committed
Update main.go
1 parent 10f09ea commit 9b52768

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cmd/slackMessageParser/main.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,32 @@ type CSVRecord struct {
7474
}
7575

7676
func main() {
77+
if _, err := os.Stat("../../SlackMessages"); os.IsNotExist(err) {
78+
log.Fatal("the ./SlackMessages directory does not exist")
79+
}
80+
7781
files, err := filepath.Glob("../../SlackMessages/*.json")
7882
if err != nil {
7983
log.Fatal(err)
8084
}
8185

8286
if len(files) == 0 {
83-
log.Fatal("Could not find *.json files in the ./SlackMessages directory")
87+
log.Fatal("could not find *.json files in the ./SlackMessages directory")
8488
}
8589

8690
messages := make([]*Message, 0)
8791

8892
for _, file := range files {
8993
bytes, err := os.ReadFile(file)
9094
if err != nil {
91-
fmt.Printf("Error occured while opening %s: %+v\n", file, err)
95+
fmt.Printf("error occured while opening %s: %+v\n", file, err)
9296
continue
9397
}
9498

9599
fileMessages := make([]*Message, 0)
96100
err = json.Unmarshal(bytes, &fileMessages)
97101
if err != nil {
98-
fmt.Printf("Error occured while parsing JSON from %s: %+v\n", file, err)
102+
fmt.Printf("error occured while parsing JSON from %s: %+v\n", file, err)
99103
continue
100104
}
101105

@@ -116,13 +120,13 @@ func main() {
116120
timeStampSplit := strings.Split(msg.TS, ".")
117121
seconds, err := strconv.ParseInt(timeStampSplit[0], 10, 64)
118122
if err != nil {
119-
fmt.Printf("Error occured while parsing seconds: %+v\n", err)
123+
fmt.Printf("error occured while parsing seconds: %+v\n", err)
120124
continue
121125
}
122126

123127
nanoseconds, err := strconv.ParseInt(timeStampSplit[1], 10, 64)
124128
if err != nil {
125-
fmt.Printf("Error occured while parsing nanoseconds: %+v\n", err)
129+
fmt.Printf("error occured while parsing nanoseconds: %+v\n", err)
126130
continue
127131
}
128132

0 commit comments

Comments
 (0)