Calculating totals

The current version of dWC.go cannot calculate totals, which can be easily solved by processing the output of dWC.go with awk:

$ go run dWC.go /tmp/swtag.log /tmp/swtag.log | awk '{sum1+=$1; sum2+=$2; sum3+=$3} END {print "\t", sum1, "\t", sum2, "\t", sum3}'
       96    550   7142

Still, this is far from being perfect and elegant!

The main reason that the current version of dWC.go cannot calculate totals is that its goroutines have no way of communicating with each other. This can be easily solved with the help of channels and pipelines. The new version of dWC.go will be called dWCtotal.go and will be presented in five parts.

The first part of dWCtotal.go is the following:

package main import ( "bufio" "fmt" "io" "os" "path/filepath" ...

Get Go Systems Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.