September 2017
Intermediate to advanced
466 pages
9h 33m
English
The first thing that you need to know in order to develop Go applications that support Unix pipes is how to read from standard input.
The developed program is named readSTDIN.go and will be presented in three parts.
The first part of the program is the expected preamble:
package main import ( "bufio" "fmt" "os" )
The second part of readSTDIN.go has the following Go code:
func main() {
filename := ""
var f *os.File
arguments := os.Args
if len(arguments) == 1 {
f = os.Stdin
} else {
filename = arguments[1]
fileHandler, err := os.Open(filename)
if err != nil {
fmt.Printf("error opening %s: %s", filename, err)
os.Exit(1)
}
f = fileHandler
}
defer f.Close()
Here, you resolve whether you have an actual file to process, ...
Read now
Unlock full access