From 88718390fa58171e8510e572fd2f49e444ce6842 Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 12 Oct 2021 23:32:30 +1300 Subject: [PATCH] Add ignore line based on regex --- src/main.go | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main.go b/src/main.go index 026ae7c..26ea176 100644 --- a/src/main.go +++ b/src/main.go @@ -11,6 +11,7 @@ import ( "strings" "syscall" "log" + "regexp" "github.com/creack/pty" ) @@ -20,7 +21,7 @@ func main() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGTERM) - var minram, maxram, args, stop, jar string + var minram, maxram, args, stop, jar, regex string for _, e := range os.Environ() { pair := strings.SplitN(e, "=", 2) switch pair[0] { @@ -34,9 +35,12 @@ func main() { stop = pair[1] case "JAR": jar = pair[1] + case "REGEX": + regex = pair[1] } - } + + log.Printf("Ram: Min: %s Max: %s Stop: %s Jar: %s\n\r", minram, maxram, stop, jar) @@ -54,8 +58,8 @@ func main() { log.Printf("Args: %s \n\r", args) } + cmd.Dir = "/server" - cmd.Stdout = os.Stdout tty, err := pty.Start(cmd) ln, _ := net.Listen("tcp", ":8081") @@ -71,6 +75,7 @@ func main() { ln.Close() }() + // capture sigterm go func() { sig := <-sigs if sig == syscall.SIGTERM { @@ -90,6 +95,22 @@ func main() { } }() + + go func() { + filter := regexp.MustCompile(regex) + if(regex != "") { + scanner := bufio.NewScanner(tty) + for scanner.Scan() { + text := scanner.Text() + if(!filter.MatchString(text)) { + fmt.Println(text) + } + } + } else { + io.Copy(os.Stdout, tty) + } + }() + go func() { io.Copy(tty, os.Stdin) }()