Add ignore line based on regex

This commit is contained in:
Jimmy 2021-10-12 23:32:30 +13:00
parent 1075fac43f
commit 88718390fa
1 changed files with 24 additions and 3 deletions

View File

@ -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)
}()