September 2017
Intermediate to advanced
466 pages
9h 33m
English
The most important information about a Unix file is its owner and its group, and this section will teach you how to find both of them using Go code. The findOG.go utility accepts a list of files as its command-line arguments and returns the owner and the group of each one of them. Its Go code will be presented in three parts.
The first part is the following:
package main import ( "fmt" "os" "path/filepath" "syscall" )
The second part is the following:
func main() { arguments := os.Args if len(arguments) == 1 { fmt.Printf("usage: %s <files>\n", filepath.Base(arguments[0])) os.Exit(1) } for _, filename := range arguments[1:] { fileInfo, err := os.Stat(filename) if err != nil { fmt.Println(err) ...Read now
Unlock full access