Skip to content

Commit 0ebc717

Browse files
feat: moved
1 parent 4c79ae8 commit 0ebc717

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

Diff for: main.go

+1-30
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"log/slog"
77
"os"
8-
"regexp"
98
"sync"
109

1110
"github.com/jasonlvhit/gocron"
@@ -29,7 +28,7 @@ func main() {
2928
validate()
3029

3130
if f.Test {
32-
testIt()
31+
pkg.TestIt(f.FilePath, f.Match)
3332
return
3433
}
3534

@@ -221,34 +220,6 @@ func notify(result *pkg.ScanResult) {
221220
}
222221
}
223222

224-
func testIt() {
225-
fps, err := pkg.FilesByPattern(f.FilePath)
226-
if err != nil {
227-
slog.Error("Error finding files", "error", err.Error())
228-
}
229-
slog.Info("Files found", "count", len(fps))
230-
for _, filePath := range fps {
231-
slog.Info("Found file", "filePath", filePath)
232-
}
233-
str := pkg.ReadFromPipeInput()
234-
if str == "" {
235-
slog.Error("No input found")
236-
slog.Info("Usage echo 'test123' | go-watch-logs --match=123 -test")
237-
return
238-
}
239-
str = str[:len(str)-1] // strip new line
240-
re, err := regexp.Compile(f.Match)
241-
if err != nil {
242-
slog.Error("Error compiling regex", "error", err.Error())
243-
return
244-
}
245-
if re.Match([]byte(str)) {
246-
slog.Info("Matched", "Match Regex", f.Match, "input", str, "Match Found", re.FindString(str))
247-
} else {
248-
slog.Warn("Not matched", "Match", f.Match, "str", str)
249-
}
250-
}
251-
252223
func flags() {
253224
flag.StringVar(&f.FilePath, "file-path", "", "full path to the log file")
254225
flag.StringVar(&f.FilePath, "f", "", "(short for --file-path) full path to the log file")

Diff for: pkg/testit.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package pkg
2+
3+
import (
4+
"log/slog"
5+
"regexp"
6+
)
7+
8+
func TestIt(filepath string, match string) {
9+
fps, err := FilesByPattern(filepath)
10+
if err != nil {
11+
slog.Error("Error finding files", "error", err.Error())
12+
}
13+
slog.Info("Files found", "count", len(fps))
14+
for _, filePath := range fps {
15+
slog.Info("Found file", "filePath", filePath)
16+
}
17+
str := ReadFromPipeInput()
18+
if str == "" {
19+
slog.Error("No input found, see --help for usage")
20+
return
21+
}
22+
str = str[:len(str)-1] // strip new line
23+
re, err := regexp.Compile(match)
24+
if err != nil {
25+
slog.Error("Error compiling regex", "error", err.Error())
26+
return
27+
}
28+
if re.Match([]byte(str)) {
29+
slog.Info("Matched", "Match Regex", match, "input", str, "Match Found", re.FindString(str))
30+
} else {
31+
slog.Warn("Not matched", "Match", match, "str", str)
32+
}
33+
}

0 commit comments

Comments
 (0)