go - Golang syntax error: unexpected EOF while writing to a file -
getting syntax error: unexpected eof
on last line of code bracket. has file io because json code worked before added in
b, err := json.marshal(gfjson) if err != nil { panic(err) filename := ".gfjson" f, err := os.create(filename) if err != nil { panic(err) } // close file on exit , check returned error defer func() { if err := f.close(); err != nil { panic(err) } }() if _, err := f.write(b); err != nil { panic(err) } fmt.fprintf(os.stdout, "gfjson file created.\n") }
you missing closing bracket on line 4 after panic.
if err != nil { panic(err) }
your code compiles fine me, because have random closing brace @ end balancing out. assume indentations close brace @ end end of function , panic should part of if statement.
Comments
Post a Comment