package main
import ( "flag" "io" "os")
func main() { inFilename := flag.String("in", "infile", "input file") outFilename := flag.String("out", "outfile", "output file") flag.Parse()
in, err := os.Open(*inFilename) if err != nil { panic(err) }
out, err := os.Create(*outFilename) if err != nil { panic(err) }
buf := make([]byte, 1024) for { n, err := in.Read(buf) if err != nil && err != io.EOF { panic(err) } if n == 0 { break } if _, err := out.Write(buf[:n]); err != nil { panic(err) } }}
$ go tool vet -shadow -shadowstrict ./cat.go ./cat.go:26: declaration of "err" shadows declaration at ./cat.go:14./cat.go:33: declaration of "err" shadows declaration at ./cat.go:26var out *os.File
out, err = os.Create(*outFilename)cat.go:33) I'd
say is correct as you don't declare a new variable hence err is
declared unnecessarily. I'm not sure if go will actually redeclare a
new var under the hood, but as err is already available just reuse
it.--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.