I am doing the basic serialization and deserialization of map as suggested in this example. But I get the following error:
panic: EOF
goroutine 1 [running]:
main.load(0x81147e0, 0x1840a378)
/home/naresh/Desktop/Work/GoEventHandler/test.go:39 +0x2cf
main.main()
/home/naresh/Desktop/Work/GoEventHandler/test.go:16 +0xe5
exit status 2
Can anyone tell me what I am doing wrong in the following code:
package main
import (
"fmt"
"bytes"
"encoding/gob"
)
func main() {
org := map[string]string{"hello": "world"}
store(org)
var loadedMap map[string]string
load(&loadedMap)
fmt.Println(loadedMap)
}
func store(data interface{}) {
m := new(bytes.Buffer)
enc := gob.NewEncoder(m)
err := enc.Encode(data)
if err != nil {
panic(err)
}
}
func load(e interface{}) {
p := new(bytes.Buffer)
dec := gob.NewDecoder(p)
err := dec.Decode(e)
if err != nil {
panic(err)
}
}