MCPcopy Create free account
hub / github.com/PacktPublishing/System-Programming-Essentials-with-Go / main

Function main

ch6/log_processing/main.go:22–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20}
21
22func 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}

Callers

nothing calls this directly

Calls 1

filterLogsFunction · 0.85

Tested by

no test coverage detected