In following code:
func ReadFile(filename string) (JPGFile, error) {
jpgFile := JPGFile{}
in, err := os.Open(filename)
defer in.Close()
if err != nil {
return jpgFile, err
}
binary.Read(in, binary.LittleEndian, &jpgFile)
return jpgFile, nil
}
binary.Read accepts "in" (os.File) as a reader, but if I pass the file as a parameter to the function I get the correct error message that "in" is not a reader as defined in the documentation: func Read(r io.Reader, order ByteOrder, data interface{}) error
In following code: func ReadFile(filename string) (JPGFile, error) { jpgFile := JPGFile{} in, err := os.Open(filename) defer in.Close() if err != nil { return jpgFile, err } binary.Read(in, binary.LittleEndian, &jpgFile) return jpgFile, nil }
binary.Read accepts "in" (os.File) as a reader, but if I pass the file as a parameter to the function I get the correct error message that "in" is not a reader as defined in the documentation: func Read(r io.Reader, order ByteOrder, data interface{}) error