Skip to content

Instantly share code, notes, and snippets.

@napsy
Created July 14, 2010 19:23
Show Gist options
  • Save napsy/475902 to your computer and use it in GitHub Desktop.
Save napsy/475902 to your computer and use it in GitHub Desktop.
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