()
| 20 | } |
| 21 | |
| 22 | func main() { |
| 23 | pipePath := "/tmp/my_log_pipe" |
| 24 | if err := os.RemoveAll(pipePath); err != nil { |
| 25 | panic(err) |
| 26 | } |
| 27 | if err := syscall.Mkfifo(pipePath, 0600); err != nil { |
| 28 | panic(err) |
| 29 | } |
| 30 | defer os.RemoveAll(pipePath) |
| 31 | |
| 32 | pipeFile, err := os.OpenFile(pipePath, os.O_RDONLY|os.O_CREATE, os.ModeNamedPipe) |
| 33 | if err != nil { |
| 34 | panic(err) |
| 35 | } |
| 36 | defer pipeFile.Close() |
| 37 | |
| 38 | go func() { |
| 39 | writer, err := os.OpenFile(pipePath, os.O_WRONLY, os.ModeNamedPipe) |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | defer writer.Close() |
| 44 | |
| 45 | for { |
| 46 | writer.WriteString("INFO: All systems operational\n") |
| 47 | writer.WriteString("ERROR: An error occurred\n") |
| 48 | time.Sleep(1 * time.Second) |
| 49 | } |
| 50 | }() |
| 51 | |
| 52 | filterLogs(pipeFile, os.Stdout) |
| 53 | } |
nothing calls this directly
no test coverage detected