-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (55 loc) · 1.47 KB
/
main.go
File metadata and controls
65 lines (55 loc) · 1.47 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
59
60
61
62
63
64
65
package main
import (
"fmt"
)
var IGNORE_PATHS = [7]string{
".git",
"build",
"dist",
"env",
"node_modules",
"target",
"venv",
}
var (
version = "development"
commit = "unknown"
date = "2024-01-01"
builtBy = "lwileczek"
)
func printBuildInfo() {
fmt.Printf("Version: %s\nCommit: %s\nBuild Date: %s | by: %s\n", version, commit, date, builtBy)
}
func main() {
cfg := parseArgs()
if cfg.Version {
printBuildInfo()
return
}
if cfg.Pattern == "" {
fmt.Println("No pattern found, please provide a search pattern")
return
}
if cfg.Insensative {
fmt.Println("WARN: case insensative search is not yet supported")
}
printCh := make(chan string, cfg.Workers)
//The system will reach deadlock if the work queue reaches capacity
workQ := make(chan string, cfg.QueueSize)
//To avoid deadlock, send tasks here which will have a non-blocky retry
//func to add tasks back to workQ
failover := make(chan string)
dirCount := make(chan int)
//Track how many dirs are open and close the work queue when we hit zero
go dirChecker(dirCount, workQ)
//Not closing as goroutines will continue to try and write if we exit early
//with the -c flag but these should be fine and killed when the program exits
//defer close(dirCount)
//defer close(failover)
go handleFailover(workQ, failover)
go createWorkerPool(cfg.Pattern, workQ, failover, printCh, dirCount, cfg.Workers)
//Send first work request
workQ <- cfg.Dir
//Print all results
showResults(printCh, &cfg.MaxResults)
}