Created
July 14, 2010 19:23
-
-
Save napsy/475902 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"encoding/binary" | |
) | |
type info struct { | |
a, b, c int32 | |
d, e, f uint8 | |
ime [3]byte | |
} | |
func write() { | |
var i info = info{1, 2, 3, 4, 5, 6, [3]byte{7, 8, 9}} | |
file, err := os.Open("/home/luka/Desktop/test.txt", os.O_CREAT | os.O_WRONLY, 0666) | |
if err != nil { | |
panic(err.String()) | |
} | |
defer file.Close() | |
err = binary.Write(file, binary.BigEndian, i) | |
if err != nil { | |
panic(err.String()) | |
} | |
} | |
func read() { | |
var i info | |
file, err := os.Open("/home/luka/Desktop/test.txt", os.O_RDONLY, 0666) | |
if err != nil { | |
panic(err.String()) | |
} | |
defer file.Close() | |
err = binary.Read(file, binary.BigEndian, i) | |
if err != nil { | |
panic(err.String()) | |
} | |
} | |
func main() { | |
write() | |
read() | |
println("Hello!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment